the*_*fog 42 linux terminal command-line ranger
我在 Linux 终端中使用Ranger 终端文件浏览器。
假设我从主目录中的命令提示符开始并启动 Ranger
user@/home/user $ ranger
Run Code Online (Sandbox Code Playgroud)
护林员打开......并在护林员计划中我探索:
/media/ubuntu/sdf675d7sf5sdfs7/some_directory
Run Code Online (Sandbox Code Playgroud)
如果我然后按 q 退出 ranger,我将返回到我从中启动 ranger 的同一个文件夹。IE
user@/home/user $
Run Code Online (Sandbox Code Playgroud)
是否可以退出护林员,并保留在我与护林员一起的目录中,我。
user@/media/ubuntu/sdf675d7sf5sdfs7/some_directory $
Run Code Online (Sandbox Code Playgroud)
Gom*_*dor 44
根据其手册
--choosedir=targetfile
Allows you to pick a directory with ranger. When you exit ranger, it will write the last visited directory into targetfile.
Run Code Online (Sandbox Code Playgroud)
所以你需要做的就是创建一个这样的别名:
alias ranger='ranger --choosedir=$HOME/.rangerdir; LASTDIR=`cat $HOME/.rangerdir`; cd "$LASTDIR"'
Run Code Online (Sandbox Code Playgroud)
建议将此别名写入您喜欢的 shell 的 rc 中。
Cir*_*郝海东 39
Shift + S
如果你点击Shift + S
,它会在当前目录上打开一个新的 shell。
然后如果你击中Ctrl + D
外壳,它会回到ranger
.
这种解决方法通常已经足够好了。
顺便说一句,我已经放弃了文件管理器几年了,我只是在我的 bashrc 中使用了这个,我只需使用选项卡完成导航目录,这对我来说已经足够了:
c() {
if [ -n "$1" ]; then
cd "$1" || return 1
else
cd ..
fi
ll
}
ll() ( ls -hl --time-style="+%Y-%m-%d_%H:%M:%S" "$@"; )
Run Code Online (Sandbox Code Playgroud)
小智 22
我找到了一个更简单的解决方案。当您安装 Ranger 时,它会在您的 bin 文件夹中放置一个脚本,如果执行该脚本,将启动该程序。但是如果你找到它,用
$ 来源游侠
当您退出时,它会启动游侠并将您放入上次访问的文件夹中。
所以如果你默认想要这种行为,就做
$别名游侠='源游侠'
或者甚至更好地将它放入您的 .bashrc 文件中。
要查看此功能的文档和实现,请阅读 bin 文件夹中的 Ranger 脚本。
我在其他地方偶然发现了一个类似的问题,与Gambai及其其他提议的变体相比,它有更好的答案。从那以后就好多了。
ranger 的 git 存储库中已有 shell 文件中的一个函数:
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"
}
Run Code Online (Sandbox Code Playgroud)
您可以将此函数放入您最喜欢的 shell rc (例如~/.zshrc
)文件中,然后创建别名和/或将其绑定到组合键(同样,两者都可以放入 rc 文件中):
alias nav=ranger-cd
Run Code Online (Sandbox Code Playgroud)
和/或
# 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-cd\n"
Run Code Online (Sandbox Code Playgroud)
免责声明:以上内容bindkey
适用于 ZSH,您应该根据您喜欢的 shell 进行更改
归档时间: |
|
查看次数: |
21647 次 |
最近记录: |