Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
Can you give details about your shell? –  Bernhard Oct 21 '12 at 12:42
2  
Did you restart the shell or source the appropriate config? –  m0nhawk Oct 21 '12 at 12:46
    
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 Oct 21 '12 at 13:01
add comment

4 Answers 4

up vote 4 down vote accepted

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.

share|improve this answer
    
Works - thanks, thanks, thanks. :] –  xliiv Oct 22 '12 at 7:05
    
Awesome way of doing !! –  pradeepchhetri Oct 22 '12 at 20:57
add comment

You can hack ~/.config/ranger/commands.py and replace the last line in shell.execute():

self.fm.execute_command(command, flags=flags)

with

self.fm.execute_command("bash -c '" + command + "'", flags=flags)

It works for me.

share|improve this answer
add comment

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|improve this answer
    
Any name for file in /etc/profile.d is acceptable? –  xliiv Oct 21 '12 at 12:58
    
@xliiv: yes name will work. –  pradeepchhetri Oct 21 '12 at 13:07
    
Alias from /etc/profile.d/name doensn't work either in bash or sh. :/ –  xliiv Oct 21 '12 at 13:32
add comment

Did you do something like? :

source /path/to/.profile

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.