How to add system alias?
Solution 1
Only interactive shells read a file that may contain alias definitions. If you want to use a nickname for a command in shell snippets executed by applications, an alias is not the right tool. Instead, write a wrapper script like this:
#!/bin/sh
gvim --remote "$@"
Call it ~/bin/grim
and make it executable. Make sure you have ~/bin
in your PATH
(you can put the script in any other directory that's in your PATH
).
If you want it to work for every user on the system, put it in /usr/local/bin
instead, ensuring that that directory is in everyone's PATH.
Solution 2
You can create a file alias.sh in /etc/profile.d
directory
Write the line
alias grim='gvim --remote'
inside that file alias.sh
This will create a system-wide customization.
Instead of alias.sh you can use any other filename ending with .sh
Related videos on Youtube
xliiv
Updated on September 18, 2022Comments
-
xliiv almost 2 years
I have this alias in my
.zshrc
:alias grim='gvim --remote'
But this is not seen from ranger file manager, I believe that ranger runs a 'generic' shell skipping my
.zshrc
. I want to make this alias visible in every shell.I added it to
~/.profile
and to/etc/zsh/zshrc
but no effect. To be specific a got this message:/bin/sh: grim: not found
-
Bernhard over 11 yearsCan you give details about your shell?
-
i31nGo over 11 yearsDid you restart the shell or
source
the appropriate config? -
xliiv over 11 yearsI use zsh. I have the alias in my .zshrc and it works. But this is not seen from ranger file manager, I believe that ranger runs a 'generic' shell skipping my .zshrc. To test my actions I open new terminal (by gnome-terminal), is it enough?
-
-
xliiv over 11 yearsAny name for file in /etc/profile.d is acceptable?
-
pradeepchhetri over 11 years@xliiv: yes name will work.
-
xliiv over 11 yearsAlias from /etc/profile.d/name doensn't work either in bash or sh. :/
-
Jortstek over 2 yearsClever. And in the config folder, so not a hack in theory.