How to add system alias?

8,832

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

Share:
8,832

Related videos on Youtube

xliiv
Author by

xliiv

Updated on September 18, 2022

Comments

  • xliiv
    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
      Bernhard over 11 years
      Can you give details about your shell?
    • i31nGo
      i31nGo over 11 years
      Did you restart the shell or source the appropriate config?
    • xliiv
      xliiv over 11 years
      I 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
    xliiv over 11 years
    Any name for file in /etc/profile.d is acceptable?
  • pradeepchhetri
    pradeepchhetri over 11 years
    @xliiv: yes name will work.
  • xliiv
    xliiv over 11 years
    Alias from /etc/profile.d/name doensn't work either in bash or sh. :/
  • Jortstek
    Jortstek over 2 years
    Clever. And in the config folder, so not a hack in theory.