summary refs log blame commit diff stats
path: root/doc/cd-after-exit.txt
blob: b13a844952aa1f20c8ab54e076ef18e1ea4a26fd (plain) (tree)
Argument passing This works well enough, but there are two remaining problems: 1. How to pass arguments to ranger? 2. How to memorize that line? Although you can just copy+paste it into your bashrc and create an alias, the complexity of the line could lead to errors. Both problems are solved by putting the command in a file: run.sh: cd "`ranger --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`" The $@ is responsible for argument passing. By using the source command, the file will be evaluated without creating a distinct new shell. bash$ source run.sh arg1 ... argN To add flexibility, replace the name "ranger" in the command to the first argument. Now it requires you to pass the name of the ranger command to the script as the first argument: run.sh: RANGER="$1" shift cd "`$RANGER --cd-after-exit \"$@\" 3>&1 1>&2 2>&3 3>&-`" == Put it in a nutshell I didn't want to have 2 files for the main program and wanted just one file at /usr/bin/ranger. So I used this trick to merge both files into one: #!/usr/bin/python """": <shell code> """ <python code> If you run this file with python, or simply by typing ranger, the program will run normally. If you, however, run this file by sourcing it into the shell, like you did with run.sh, the cd-after-exit mode will be activated. Now the way of running ranger with the cd-after-exit feature is: bash$ source /path/to/ranger.py /path/to/ranger.py or, if properly installed: bash$ source ranger ranger A convenient way of using this feature is adding this line to your bashrc: alias rn='source ranger ranger' == Open issues Unfortunately there is some redundancy: you have to type the path to ranger twice. I know of no way to fix this, because it is not possible to get the filename of the file currently being sourced. Example: bash$ echo 'source sourced.sh' > main.sh bash$ echo 'echo $0 $@' > sourced.sh bash$ bash main.sh main.sh If you find a way to make this print out 'sourced.sh', let me know. :) Another thing: If Ctrl+C is pressed anywhere in the program, the execution of the sourced shell script is stopped and the feature stops working. Dec 25, 2009