How to exit the Ranger file explorer back to command prompt but keep the current directory?
I am using Ranger terminal file explorer from within a linux terminal.
Say I start from command prompt in home directory and launch ranger
user@/home/user $ ranger
ranger opens..... and within the ranger program I explore to:
/media/ubuntu/sdf675d7sf5sdfs7/some_directory
If I then hit q to quit ranger, I am dropped back to the same folder I launched ranger from. i.e.
user@/home/user $
Is it possible to quit ranger, and remain in the directory I was in with ranger, i.
user@/media/ubuntu/sdf675d7sf5sdfs7/some_directory $
linux command-line terminal ranger
add a comment |
I am using Ranger terminal file explorer from within a linux terminal.
Say I start from command prompt in home directory and launch ranger
user@/home/user $ ranger
ranger opens..... and within the ranger program I explore to:
/media/ubuntu/sdf675d7sf5sdfs7/some_directory
If I then hit q to quit ranger, I am dropped back to the same folder I launched ranger from. i.e.
user@/home/user $
Is it possible to quit ranger, and remain in the directory I was in with ranger, i.
user@/media/ubuntu/sdf675d7sf5sdfs7/some_directory $
linux command-line terminal ranger
add a comment |
I am using Ranger terminal file explorer from within a linux terminal.
Say I start from command prompt in home directory and launch ranger
user@/home/user $ ranger
ranger opens..... and within the ranger program I explore to:
/media/ubuntu/sdf675d7sf5sdfs7/some_directory
If I then hit q to quit ranger, I am dropped back to the same folder I launched ranger from. i.e.
user@/home/user $
Is it possible to quit ranger, and remain in the directory I was in with ranger, i.
user@/media/ubuntu/sdf675d7sf5sdfs7/some_directory $
linux command-line terminal ranger
I am using Ranger terminal file explorer from within a linux terminal.
Say I start from command prompt in home directory and launch ranger
user@/home/user $ ranger
ranger opens..... and within the ranger program I explore to:
/media/ubuntu/sdf675d7sf5sdfs7/some_directory
If I then hit q to quit ranger, I am dropped back to the same folder I launched ranger from. i.e.
user@/home/user $
Is it possible to quit ranger, and remain in the directory I was in with ranger, i.
user@/media/ubuntu/sdf675d7sf5sdfs7/some_directory $
linux command-line terminal ranger
linux command-line terminal ranger
edited Jun 4 '18 at 9:22
Ciro Santilli 新疆改造中心 六四事件 法轮功
4,12322736
4,12322736
asked Feb 22 '16 at 1:36
the_velour_fogthe_velour_fog
1,9091917
1,9091917
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
According to its manual
--choosedir=targetfile
Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into targetfile.
So all you need to do is create an alias like this:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
And writing this alias into the rc of your favoured shell is recommended.
2
wow thats pretty clever, It never occurred to me you could issue a command to a program, terminate it with a;and then specify more commands after the semi-colon which - Im assuming are run at the point you closeranger, thanks!
– the_velour_fog
Feb 22 '16 at 3:25
1
Consider using.rangerdirinstead to make it hidden. Or delete it at the end,rm -d $HOME/rangerdir.
– Mateen Ulhaq
Jan 25 '18 at 9:35
This is great but it if I understand it correctly, this would mean that you have that behavior permanently. If would be nice if there was a way to have the option to exit into current ranger directory OR the directory you were in when you started ranger.
– neverfox
Mar 21 '18 at 18:15
neverfox Once you create an alias, it's up to you if you offer the selection of the directory to land in inside that alias. The selection can be made before the binary is called or after it's finished.
– Gombai Sándor
Mar 26 '18 at 18:14
Thank you for this awesome solution! I happen to be using the fish shell, so to set my alias, I usedfish_configand added an abbreviation forranger --choosedir="$HOME/.rangerdir"; cd (cat $HOME/.rangerdir)
– rockzombie2
Nov 16 '18 at 5:34
add a comment |
S
If you hit S, it opens a new shell on the current directory.
Then if you hit Ctrl + D on the shell, it goes back to ranger.
This workaround is often good enough.
add a comment |
I found an easier solution. When you install ranger, it will put a script in your bin folder which, if executed, will start the program. But if you source it, with
$ source ranger
it will launch ranger and drop you in the last visited folder when you exit.
so if you want this behavior by default, just do
$ alias ranger='source ranger'
or even better put it into your .bashrc file.
To see the documentation and implementation for this feature, read the ranger script in your bin folder.
add a comment |
To piggy back of of Gombai Sándor's answer, i suggest making a minor adjustment to the alias:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
By changing "$Home/rangerdir" to "$Home/.rangerdir" you make the file created by the alias hidden. just makes it so it is not annoyingly cluttering up the home folder. it makes no functional difference to how it works.
add a comment |
Thanks for Gombai for the inspiration, but on Ubuntu 14.04 LTS I found the solution didn't quite work. Modifying it slightly and saving as an alias in my .bashrc, the following worked perfectly (after creating the rangerdir file):
alias ranger='ranger --choosedir=$HOME/rangerdir;cd "$(cat $HOME/rangerdir)"'
The following post on askubuntu helped me out when I was trying to figure out why different solutions I was trying weren't working: https://askubuntu.com/questions/404141/why-cant-i-pipe-into-cd
add a comment |
I stumbled upon a similar question elsewhere with better answer compared to Gambai and its other proposed variants. It is better since.
- it will take care of the created file by putting it into the tmp folder so that it can be deleted by the system
- it is more clean code (although the Gambai's answer can be converted to a function)
There is a function in a shell file already in ranger's git repo:
https://github.com/ranger/ranger/blob/master/examples/bash_automatic_cd.sh
function ranger-cd {
# create a temp file and store the name
tempfile="$(mktemp -t tmp.XXXXXX)"
# run ranger and ask it to output the last path into the
# temp file
ranger --choosedir="$tempfile" "${@:-$(pwd)}"
# if the temp file exists read and the content of the temp
# file was not equal to the current path
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
# change directory to the path in the temp file
cd -- "$(cat "$tempfile")"
fi
# its not super necessary to have this line for deleting
# the temp file since Linux should handle it on the next
# boot
rm -f -- "$tempfile"
}
You can put this function in your favorite's shell rc (for example ~/.zshrc) file and either create alias and/or bind it to a key combination (again both can go in the rc file):
alias nav=ranger-cd
and/or
# This will run the function by Ctrl+O through returning
# the string "ranger-cd" in addition to a new-line character
# to act as Enter key-press
bindkey -s "^o" "ranger-cdn"
Disclaimer: the bindkey above works in ZSH and you should change it based on your preferred shell
add a comment |
This is a bit old now but I ended up here with the same problem. Ciro Santilli stated above that if you hit "S" when in ranger it opens in a new shell. Well on my system hitting "S" on a directory opens the directory in the current shell, exactly what I wanted it to do.
Hope this helps other people.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1043806%2fhow-to-exit-the-ranger-file-explorer-back-to-command-prompt-but-keep-the-current%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
According to its manual
--choosedir=targetfile
Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into targetfile.
So all you need to do is create an alias like this:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
And writing this alias into the rc of your favoured shell is recommended.
2
wow thats pretty clever, It never occurred to me you could issue a command to a program, terminate it with a;and then specify more commands after the semi-colon which - Im assuming are run at the point you closeranger, thanks!
– the_velour_fog
Feb 22 '16 at 3:25
1
Consider using.rangerdirinstead to make it hidden. Or delete it at the end,rm -d $HOME/rangerdir.
– Mateen Ulhaq
Jan 25 '18 at 9:35
This is great but it if I understand it correctly, this would mean that you have that behavior permanently. If would be nice if there was a way to have the option to exit into current ranger directory OR the directory you were in when you started ranger.
– neverfox
Mar 21 '18 at 18:15
neverfox Once you create an alias, it's up to you if you offer the selection of the directory to land in inside that alias. The selection can be made before the binary is called or after it's finished.
– Gombai Sándor
Mar 26 '18 at 18:14
Thank you for this awesome solution! I happen to be using the fish shell, so to set my alias, I usedfish_configand added an abbreviation forranger --choosedir="$HOME/.rangerdir"; cd (cat $HOME/.rangerdir)
– rockzombie2
Nov 16 '18 at 5:34
add a comment |
According to its manual
--choosedir=targetfile
Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into targetfile.
So all you need to do is create an alias like this:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
And writing this alias into the rc of your favoured shell is recommended.
2
wow thats pretty clever, It never occurred to me you could issue a command to a program, terminate it with a;and then specify more commands after the semi-colon which - Im assuming are run at the point you closeranger, thanks!
– the_velour_fog
Feb 22 '16 at 3:25
1
Consider using.rangerdirinstead to make it hidden. Or delete it at the end,rm -d $HOME/rangerdir.
– Mateen Ulhaq
Jan 25 '18 at 9:35
This is great but it if I understand it correctly, this would mean that you have that behavior permanently. If would be nice if there was a way to have the option to exit into current ranger directory OR the directory you were in when you started ranger.
– neverfox
Mar 21 '18 at 18:15
neverfox Once you create an alias, it's up to you if you offer the selection of the directory to land in inside that alias. The selection can be made before the binary is called or after it's finished.
– Gombai Sándor
Mar 26 '18 at 18:14
Thank you for this awesome solution! I happen to be using the fish shell, so to set my alias, I usedfish_configand added an abbreviation forranger --choosedir="$HOME/.rangerdir"; cd (cat $HOME/.rangerdir)
– rockzombie2
Nov 16 '18 at 5:34
add a comment |
According to its manual
--choosedir=targetfile
Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into targetfile.
So all you need to do is create an alias like this:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
And writing this alias into the rc of your favoured shell is recommended.
According to its manual
--choosedir=targetfile
Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into targetfile.
So all you need to do is create an alias like this:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
And writing this alias into the rc of your favoured shell is recommended.
edited Jan 25 '18 at 9:37
Mateen Ulhaq
2,46952951
2,46952951
answered Feb 22 '16 at 3:15
Gombai SándorGombai Sándor
3,0551813
3,0551813
2
wow thats pretty clever, It never occurred to me you could issue a command to a program, terminate it with a;and then specify more commands after the semi-colon which - Im assuming are run at the point you closeranger, thanks!
– the_velour_fog
Feb 22 '16 at 3:25
1
Consider using.rangerdirinstead to make it hidden. Or delete it at the end,rm -d $HOME/rangerdir.
– Mateen Ulhaq
Jan 25 '18 at 9:35
This is great but it if I understand it correctly, this would mean that you have that behavior permanently. If would be nice if there was a way to have the option to exit into current ranger directory OR the directory you were in when you started ranger.
– neverfox
Mar 21 '18 at 18:15
neverfox Once you create an alias, it's up to you if you offer the selection of the directory to land in inside that alias. The selection can be made before the binary is called or after it's finished.
– Gombai Sándor
Mar 26 '18 at 18:14
Thank you for this awesome solution! I happen to be using the fish shell, so to set my alias, I usedfish_configand added an abbreviation forranger --choosedir="$HOME/.rangerdir"; cd (cat $HOME/.rangerdir)
– rockzombie2
Nov 16 '18 at 5:34
add a comment |
2
wow thats pretty clever, It never occurred to me you could issue a command to a program, terminate it with a;and then specify more commands after the semi-colon which - Im assuming are run at the point you closeranger, thanks!
– the_velour_fog
Feb 22 '16 at 3:25
1
Consider using.rangerdirinstead to make it hidden. Or delete it at the end,rm -d $HOME/rangerdir.
– Mateen Ulhaq
Jan 25 '18 at 9:35
This is great but it if I understand it correctly, this would mean that you have that behavior permanently. If would be nice if there was a way to have the option to exit into current ranger directory OR the directory you were in when you started ranger.
– neverfox
Mar 21 '18 at 18:15
neverfox Once you create an alias, it's up to you if you offer the selection of the directory to land in inside that alias. The selection can be made before the binary is called or after it's finished.
– Gombai Sándor
Mar 26 '18 at 18:14
Thank you for this awesome solution! I happen to be using the fish shell, so to set my alias, I usedfish_configand added an abbreviation forranger --choosedir="$HOME/.rangerdir"; cd (cat $HOME/.rangerdir)
– rockzombie2
Nov 16 '18 at 5:34
2
2
wow thats pretty clever, It never occurred to me you could issue a command to a program, terminate it with a
; and then specify more commands after the semi-colon which - Im assuming are run at the point you close ranger , thanks!– the_velour_fog
Feb 22 '16 at 3:25
wow thats pretty clever, It never occurred to me you could issue a command to a program, terminate it with a
; and then specify more commands after the semi-colon which - Im assuming are run at the point you close ranger , thanks!– the_velour_fog
Feb 22 '16 at 3:25
1
1
Consider using
.rangerdir instead to make it hidden. Or delete it at the end, rm -d $HOME/rangerdir.– Mateen Ulhaq
Jan 25 '18 at 9:35
Consider using
.rangerdir instead to make it hidden. Or delete it at the end, rm -d $HOME/rangerdir.– Mateen Ulhaq
Jan 25 '18 at 9:35
This is great but it if I understand it correctly, this would mean that you have that behavior permanently. If would be nice if there was a way to have the option to exit into current ranger directory OR the directory you were in when you started ranger.
– neverfox
Mar 21 '18 at 18:15
This is great but it if I understand it correctly, this would mean that you have that behavior permanently. If would be nice if there was a way to have the option to exit into current ranger directory OR the directory you were in when you started ranger.
– neverfox
Mar 21 '18 at 18:15
neverfox Once you create an alias, it's up to you if you offer the selection of the directory to land in inside that alias. The selection can be made before the binary is called or after it's finished.
– Gombai Sándor
Mar 26 '18 at 18:14
neverfox Once you create an alias, it's up to you if you offer the selection of the directory to land in inside that alias. The selection can be made before the binary is called or after it's finished.
– Gombai Sándor
Mar 26 '18 at 18:14
Thank you for this awesome solution! I happen to be using the fish shell, so to set my alias, I used
fish_config and added an abbreviation for ranger --choosedir="$HOME/.rangerdir"; cd (cat $HOME/.rangerdir)– rockzombie2
Nov 16 '18 at 5:34
Thank you for this awesome solution! I happen to be using the fish shell, so to set my alias, I used
fish_config and added an abbreviation for ranger --choosedir="$HOME/.rangerdir"; cd (cat $HOME/.rangerdir)– rockzombie2
Nov 16 '18 at 5:34
add a comment |
S
If you hit S, it opens a new shell on the current directory.
Then if you hit Ctrl + D on the shell, it goes back to ranger.
This workaround is often good enough.
add a comment |
S
If you hit S, it opens a new shell on the current directory.
Then if you hit Ctrl + D on the shell, it goes back to ranger.
This workaround is often good enough.
add a comment |
S
If you hit S, it opens a new shell on the current directory.
Then if you hit Ctrl + D on the shell, it goes back to ranger.
This workaround is often good enough.
S
If you hit S, it opens a new shell on the current directory.
Then if you hit Ctrl + D on the shell, it goes back to ranger.
This workaround is often good enough.
answered Aug 26 '17 at 6:24
Ciro Santilli 新疆改造中心 六四事件 法轮功Ciro Santilli 新疆改造中心 六四事件 法轮功
4,12322736
4,12322736
add a comment |
add a comment |
I found an easier solution. When you install ranger, it will put a script in your bin folder which, if executed, will start the program. But if you source it, with
$ source ranger
it will launch ranger and drop you in the last visited folder when you exit.
so if you want this behavior by default, just do
$ alias ranger='source ranger'
or even better put it into your .bashrc file.
To see the documentation and implementation for this feature, read the ranger script in your bin folder.
add a comment |
I found an easier solution. When you install ranger, it will put a script in your bin folder which, if executed, will start the program. But if you source it, with
$ source ranger
it will launch ranger and drop you in the last visited folder when you exit.
so if you want this behavior by default, just do
$ alias ranger='source ranger'
or even better put it into your .bashrc file.
To see the documentation and implementation for this feature, read the ranger script in your bin folder.
add a comment |
I found an easier solution. When you install ranger, it will put a script in your bin folder which, if executed, will start the program. But if you source it, with
$ source ranger
it will launch ranger and drop you in the last visited folder when you exit.
so if you want this behavior by default, just do
$ alias ranger='source ranger'
or even better put it into your .bashrc file.
To see the documentation and implementation for this feature, read the ranger script in your bin folder.
I found an easier solution. When you install ranger, it will put a script in your bin folder which, if executed, will start the program. But if you source it, with
$ source ranger
it will launch ranger and drop you in the last visited folder when you exit.
so if you want this behavior by default, just do
$ alias ranger='source ranger'
or even better put it into your .bashrc file.
To see the documentation and implementation for this feature, read the ranger script in your bin folder.
answered Jun 8 '18 at 13:45
Ogino KnausOgino Knaus
6112
6112
add a comment |
add a comment |
To piggy back of of Gombai Sándor's answer, i suggest making a minor adjustment to the alias:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
By changing "$Home/rangerdir" to "$Home/.rangerdir" you make the file created by the alias hidden. just makes it so it is not annoyingly cluttering up the home folder. it makes no functional difference to how it works.
add a comment |
To piggy back of of Gombai Sándor's answer, i suggest making a minor adjustment to the alias:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
By changing "$Home/rangerdir" to "$Home/.rangerdir" you make the file created by the alias hidden. just makes it so it is not annoyingly cluttering up the home folder. it makes no functional difference to how it works.
add a comment |
To piggy back of of Gombai Sándor's answer, i suggest making a minor adjustment to the alias:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
By changing "$Home/rangerdir" to "$Home/.rangerdir" you make the file created by the alias hidden. just makes it so it is not annoyingly cluttering up the home folder. it makes no functional difference to how it works.
To piggy back of of Gombai Sándor's answer, i suggest making a minor adjustment to the alias:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
By changing "$Home/rangerdir" to "$Home/.rangerdir" you make the file created by the alias hidden. just makes it so it is not annoyingly cluttering up the home folder. it makes no functional difference to how it works.
answered Jul 19 '17 at 14:30
dduxxdduxx
411
411
add a comment |
add a comment |
Thanks for Gombai for the inspiration, but on Ubuntu 14.04 LTS I found the solution didn't quite work. Modifying it slightly and saving as an alias in my .bashrc, the following worked perfectly (after creating the rangerdir file):
alias ranger='ranger --choosedir=$HOME/rangerdir;cd "$(cat $HOME/rangerdir)"'
The following post on askubuntu helped me out when I was trying to figure out why different solutions I was trying weren't working: https://askubuntu.com/questions/404141/why-cant-i-pipe-into-cd
add a comment |
Thanks for Gombai for the inspiration, but on Ubuntu 14.04 LTS I found the solution didn't quite work. Modifying it slightly and saving as an alias in my .bashrc, the following worked perfectly (after creating the rangerdir file):
alias ranger='ranger --choosedir=$HOME/rangerdir;cd "$(cat $HOME/rangerdir)"'
The following post on askubuntu helped me out when I was trying to figure out why different solutions I was trying weren't working: https://askubuntu.com/questions/404141/why-cant-i-pipe-into-cd
add a comment |
Thanks for Gombai for the inspiration, but on Ubuntu 14.04 LTS I found the solution didn't quite work. Modifying it slightly and saving as an alias in my .bashrc, the following worked perfectly (after creating the rangerdir file):
alias ranger='ranger --choosedir=$HOME/rangerdir;cd "$(cat $HOME/rangerdir)"'
The following post on askubuntu helped me out when I was trying to figure out why different solutions I was trying weren't working: https://askubuntu.com/questions/404141/why-cant-i-pipe-into-cd
Thanks for Gombai for the inspiration, but on Ubuntu 14.04 LTS I found the solution didn't quite work. Modifying it slightly and saving as an alias in my .bashrc, the following worked perfectly (after creating the rangerdir file):
alias ranger='ranger --choosedir=$HOME/rangerdir;cd "$(cat $HOME/rangerdir)"'
The following post on askubuntu helped me out when I was trying to figure out why different solutions I was trying weren't working: https://askubuntu.com/questions/404141/why-cant-i-pipe-into-cd
edited Dec 5 '17 at 17:16
answered Mar 11 '17 at 18:32
garzaigarzai
463
463
add a comment |
add a comment |
I stumbled upon a similar question elsewhere with better answer compared to Gambai and its other proposed variants. It is better since.
- it will take care of the created file by putting it into the tmp folder so that it can be deleted by the system
- it is more clean code (although the Gambai's answer can be converted to a function)
There is a function in a shell file already in ranger's git repo:
https://github.com/ranger/ranger/blob/master/examples/bash_automatic_cd.sh
function ranger-cd {
# create a temp file and store the name
tempfile="$(mktemp -t tmp.XXXXXX)"
# run ranger and ask it to output the last path into the
# temp file
ranger --choosedir="$tempfile" "${@:-$(pwd)}"
# if the temp file exists read and the content of the temp
# file was not equal to the current path
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
# change directory to the path in the temp file
cd -- "$(cat "$tempfile")"
fi
# its not super necessary to have this line for deleting
# the temp file since Linux should handle it on the next
# boot
rm -f -- "$tempfile"
}
You can put this function in your favorite's shell rc (for example ~/.zshrc) file and either create alias and/or bind it to a key combination (again both can go in the rc file):
alias nav=ranger-cd
and/or
# This will run the function by Ctrl+O through returning
# the string "ranger-cd" in addition to a new-line character
# to act as Enter key-press
bindkey -s "^o" "ranger-cdn"
Disclaimer: the bindkey above works in ZSH and you should change it based on your preferred shell
add a comment |
I stumbled upon a similar question elsewhere with better answer compared to Gambai and its other proposed variants. It is better since.
- it will take care of the created file by putting it into the tmp folder so that it can be deleted by the system
- it is more clean code (although the Gambai's answer can be converted to a function)
There is a function in a shell file already in ranger's git repo:
https://github.com/ranger/ranger/blob/master/examples/bash_automatic_cd.sh
function ranger-cd {
# create a temp file and store the name
tempfile="$(mktemp -t tmp.XXXXXX)"
# run ranger and ask it to output the last path into the
# temp file
ranger --choosedir="$tempfile" "${@:-$(pwd)}"
# if the temp file exists read and the content of the temp
# file was not equal to the current path
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
# change directory to the path in the temp file
cd -- "$(cat "$tempfile")"
fi
# its not super necessary to have this line for deleting
# the temp file since Linux should handle it on the next
# boot
rm -f -- "$tempfile"
}
You can put this function in your favorite's shell rc (for example ~/.zshrc) file and either create alias and/or bind it to a key combination (again both can go in the rc file):
alias nav=ranger-cd
and/or
# This will run the function by Ctrl+O through returning
# the string "ranger-cd" in addition to a new-line character
# to act as Enter key-press
bindkey -s "^o" "ranger-cdn"
Disclaimer: the bindkey above works in ZSH and you should change it based on your preferred shell
add a comment |
I stumbled upon a similar question elsewhere with better answer compared to Gambai and its other proposed variants. It is better since.
- it will take care of the created file by putting it into the tmp folder so that it can be deleted by the system
- it is more clean code (although the Gambai's answer can be converted to a function)
There is a function in a shell file already in ranger's git repo:
https://github.com/ranger/ranger/blob/master/examples/bash_automatic_cd.sh
function ranger-cd {
# create a temp file and store the name
tempfile="$(mktemp -t tmp.XXXXXX)"
# run ranger and ask it to output the last path into the
# temp file
ranger --choosedir="$tempfile" "${@:-$(pwd)}"
# if the temp file exists read and the content of the temp
# file was not equal to the current path
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
# change directory to the path in the temp file
cd -- "$(cat "$tempfile")"
fi
# its not super necessary to have this line for deleting
# the temp file since Linux should handle it on the next
# boot
rm -f -- "$tempfile"
}
You can put this function in your favorite's shell rc (for example ~/.zshrc) file and either create alias and/or bind it to a key combination (again both can go in the rc file):
alias nav=ranger-cd
and/or
# This will run the function by Ctrl+O through returning
# the string "ranger-cd" in addition to a new-line character
# to act as Enter key-press
bindkey -s "^o" "ranger-cdn"
Disclaimer: the bindkey above works in ZSH and you should change it based on your preferred shell
I stumbled upon a similar question elsewhere with better answer compared to Gambai and its other proposed variants. It is better since.
- it will take care of the created file by putting it into the tmp folder so that it can be deleted by the system
- it is more clean code (although the Gambai's answer can be converted to a function)
There is a function in a shell file already in ranger's git repo:
https://github.com/ranger/ranger/blob/master/examples/bash_automatic_cd.sh
function ranger-cd {
# create a temp file and store the name
tempfile="$(mktemp -t tmp.XXXXXX)"
# run ranger and ask it to output the last path into the
# temp file
ranger --choosedir="$tempfile" "${@:-$(pwd)}"
# if the temp file exists read and the content of the temp
# file was not equal to the current path
test -f "$tempfile" &&
if [ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]; then
# change directory to the path in the temp file
cd -- "$(cat "$tempfile")"
fi
# its not super necessary to have this line for deleting
# the temp file since Linux should handle it on the next
# boot
rm -f -- "$tempfile"
}
You can put this function in your favorite's shell rc (for example ~/.zshrc) file and either create alias and/or bind it to a key combination (again both can go in the rc file):
alias nav=ranger-cd
and/or
# This will run the function by Ctrl+O through returning
# the string "ranger-cd" in addition to a new-line character
# to act as Enter key-press
bindkey -s "^o" "ranger-cdn"
Disclaimer: the bindkey above works in ZSH and you should change it based on your preferred shell
answered Jan 23 at 10:13
Mehrad MahmoudianMehrad Mahmoudian
1355
1355
add a comment |
add a comment |
This is a bit old now but I ended up here with the same problem. Ciro Santilli stated above that if you hit "S" when in ranger it opens in a new shell. Well on my system hitting "S" on a directory opens the directory in the current shell, exactly what I wanted it to do.
Hope this helps other people.
add a comment |
This is a bit old now but I ended up here with the same problem. Ciro Santilli stated above that if you hit "S" when in ranger it opens in a new shell. Well on my system hitting "S" on a directory opens the directory in the current shell, exactly what I wanted it to do.
Hope this helps other people.
add a comment |
This is a bit old now but I ended up here with the same problem. Ciro Santilli stated above that if you hit "S" when in ranger it opens in a new shell. Well on my system hitting "S" on a directory opens the directory in the current shell, exactly what I wanted it to do.
Hope this helps other people.
This is a bit old now but I ended up here with the same problem. Ciro Santilli stated above that if you hit "S" when in ranger it opens in a new shell. Well on my system hitting "S" on a directory opens the directory in the current shell, exactly what I wanted it to do.
Hope this helps other people.
answered Oct 12 '18 at 12:53
girvaingirvain
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1043806%2fhow-to-exit-the-ranger-file-explorer-back-to-command-prompt-but-keep-the-current%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown