I have defined some aliases and function snippets int some of my profile files, say, ~/.zprofile. But Emacs never reads them. There is already a topic about it. However, it's not enough:
It cannot source completely .zshrc and would emit errors for
compinit and the like.
Seems this approach only works for environment VARIABLES.
So in shell-mode or run command in Emacs(Alt-!) the effect is still different with that in terminal(emulators).
So is there any way to deal with the problem? Thanks.
You can create a file ~/.emacs_zsh (or .emacs_bash, emacs_sh, ...) that shell-mode will use on startup. My .emacs_bash is simply:
. ~/.profile
Just be sure to put a newline at the end of the sourcing line or it won't get executed.
Related
I am trying to refresh my aliases on my Mac (OS Catalina 10.15.6) after defining new aliases in my .bash_profile file with the command:
source ~/.bash_profile
But terminal keeps giving this error message:-bash: s: command not found
This is confusing because for the longest time this command worked. I even had it included in my .bash_profile file as an alias, where it worked fine.
I'm aware the problem could have to do it with an error in my PATH but I've never made any edits to my PATH so have no idea what the issue could be?
Thanks in advance.
My first instinct would be to check both ~/.bashrc, and /etc/bashrc if it exists. That is where I customarily define aliases, and it looks to me as though a bad alias may be your problem.
I'm not saying it was the one you made, although it might be. Just go through your rc and profile files and look for any aliases which might in any way clash with source.
I suspect the source command is working just fine and the problem is a bad line in the ~/.bash_profile itself that looks like it's trying to run a command named s. I would look in there for the problem.
It might help to run it with xtrace on via bash -x ~/.bash_profile – running it in a separate process like that won't have any of the presumably-desired side effects of sourceing it in your current shell, but you can see what it's trying to do so that you can fix it.
(You can also just set -x before the source and get both xtrace and running in the current shell; just be sure to set +x afterwards or your shell session will be full of debug output.)
I added a bunch of aliases to my .profile file. None of them work either.
My .bash_profile has one line: export PATH="$HOME/.npm-packages/bin:$PATH"
I went as far as creating a .bashrc file and putting source ~/.bash_profile in it.
Nothing I have tried is working, other than if I put source ~/.bash_profile into my shell every time I open a new one.
I have tried every stack overflow answer I could find and nothing is working.
Anyone out there can help me?
I am on mac, using fish, but same results in bash.
Fish is not, in general, bash compatible. That means it won't read bash's configuration files and if source works on them that's lucky (e.g. export var=val will work, var=val will not).
You need to either start fish from bash (and have all necessary variables exported), rewrite the necessary configuration for use with fish and add it to config.fish, or use something like https://github.com/edc/bass to read bash's changed environment from fish.
I've got a makefile for installing my personal repo of config files, part of which is compiling my emacs scripts:
compile:
emacs -batch --eval "(progn (load \"~/.emacs\") (byte-recompile-directory \"~/.emacs.d\" 0))"
The problem is, on OSX, I have an alias called "emacs" that points to the Emacs.app binary for use in a terminal, this is defined in my ~/.bash_profile.
Now, no matter what I do, I can't seem to get the shell that Make is calling to read a startup file to load that alias, so that compilation step always fails.
Does anyone know how to do this?
.bash_profile is only read by interactive login shells. Exported environment variables set in it are inherited through the process environment, which means that these settings are generally available to all programs the user starts (if bash is indeed the login shell, of course).
No such inheritance happens for aliases, though. Bash supports exported functions, but that's an obscure feature which can easily break other programs (for example, those which assume that environment variable values do not contain newlines). If you go that route, you may have to use .bashrc instead, to make sure that these functions are exported by interactive bash shells which are not login shells.
I expected the easiest solution is to put a directory like $HOME/bin on the PATH (in .bash_profile or .bashrc, whatever works best) and put an emacs wrapper script into that directory which invokes the actual binary using exec /path/to/Emacs.app "$#" (or maybe just a symbolic link would do).
That is very strange. Aliases are not exported to sub-shells, and the .bash_profile script is only run by interactive shells: make doesn't invoke an interactive shell (by default). So, it's hard to understand how the shell make invokes would see that alias based on the information you've provided.
Maybe you set the BASH_ENV shell variable somewhere? You should never do that, unless you really know what you're doing.
Maybe you reset make's .SHELLFLAGS variable to force a login shell? You shouldn't to that either.
Anyway, you can try using command which avoids aliases etc. Unfortunately make doesn't know this is a shell-built in, so you have to convince it to run a shell. This will be fixed in the next release of GNU make but Apple will never ship that.
compile:
command emacs -batch --eval "(progn (load \"~/.emacs\") (byte-recompile-directory \"~/.emacs.d\" 0))" && true
I have added several aliases to my .zshrc file and they ONLY work if I restart terminal or use the source ~/.zshrc If I just open terminal, then type the alias, it will not recognize it, until I call source ~/.zshrc
So I know it's not a problem with the alias I created, I just have to load up the .zshrc file every time I want to use them.
What is going on? How can I fix this?
Well, you don't expect that you only have to edit a file and then, by magic, all your current zsh instances somehow ingest the changes, do you?
From the zsh man page, section STARTUP/SHUTDOWN FILES :
if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc
($ZDOTDIR defaults to your $HOME). Hence, if you are in your terminal, you have three choices. Two of them you already found out (restart the terminal, source .zshrc manually). The third choice would be to just open a zsh subshell (by typing zsh).
Actually, there is a trick to do some "magic" in reading the file automatically: Zsh allows you to define a so-called precmd hook, which allows you to establish an arbitrary command to be executed just before a command prompt will be displayed. You could use it to source any file you like. If you want to use this feature, I strongly recommend against sourcing all of .zshrc. Sooner or later, you will have stuff in .zshrc that you don't want to be executed every time.
Instead, put your alias definitions into a separate file, say $HOME/.aliases, and in Zsh define the hook
function precmd {
source $HOME/.aliases
}
If you later change the .aliases file, you would still have to type a Carriage Return in your shell, in order to provoke a new prompt to be written and the precmd to be executed, but this is less cumbersome than sourcing the file manually.
I would like to configure my bash shell to expand partially entered tree structure like it does emacs "minibuffer-complete" command.
Imagine I have two folders, foo1 and foo2. foo1 contains a subfolder sub1, and foo2 contains subfolder wow. So I have:
foo1/sub1/
foo2/wow/
Now when opening a file in emacs if I type
f/w
and press TAB it will automatically expand it to "foo1/wow/".
I would like to have a similar functionality in bash. Any ideas?
Whilst I don't know how to do this in bash, or even if it's possible, I know that if you change your shell to zsh, it can be done.
It's not enabled by default, and I'm not sure how to enable it either, but I use the zsh grml config, which enables the kind of expansion you're talking about.
Zsh, especially combined with said config, also has many other helpful features.
If you're not willing to change shell, then this isn't a helpful answer I'm afraid.
you can have it the other way around, using emacs M-x shell command. It open a Shell buffer with an autocompletion like in the minibuffer
Disclosure: I am the author of the project
I have written the completion functions necessary to enable such completion in bash: https://github.com/sio/bash-complete-partial-path
Hope you'll find this project useful