nnn
nnn(也被样式化为 n³)是一个用 C 语言编写的便携式终端文件管理器。它可以通过扁平文本插件系统轻松扩展,在已有插件(包括 (neo)vim 插件)的基础上添加自己的语言脚本。
nnn features native archiving/decompression to and from commonly installed formats such as xz, disk usage analysis and a fuzzy app launcher, a batch file renamer and a file picker through its plugin architecture. nnn supports instant search-as-you-type with regex (or simple string) filters and a navigate-as-you-type mode for continuous navigation in filter mode with directory auto-select. Also supported are contexts, bookmarks, multiple sorting options, SSHFS, batch operations on selections (a group of selected files) and a lot more.
尽管 nnn 功能强大,但其设计简单易用,可通过环境变量进行配置,无需使用配置文件。
安装[编辑 | 编辑源代码]
安装 nnn包 软件包,或 安装 nnn-gitAUR 以获取开发版本。
用法[编辑 | 编辑源代码]
nnn 可以用类 vi 按键 hjkl
或 arrow keys
控制。请勿记忆按键:箭头、/
和 q
即可。请随时按 ?
获取键盘快捷键帮助。
配置[编辑 | 编辑源代码]
nnn 通过环境变量进行配置。有关这些设置的详细信息,请参阅 nnn(1) 以及 nnn wiki。
NNN_BMS='d:~/Documents;u:/home/user/Cam Uploads;D:~/Downloads/' NNN_SSHFS="sshfs -o follow_symlinks" # make sshfs follow symlinks on the remote NNN_COLORS="2136" # use a different color for each context NNN_TRASH=1 # trash (needs trash-cli) instead of delete
nnn.desktop
from a desktop environment started from a display manager, .bashrc
may not be sourced. In this case, see the upstream instructions for desktop integration.NNN_BMS
变量是比较有用的设置之一,它可以让你选择快捷方式快速跳转到书签目录。您可以使用 b
后跟一个您指定的字母。在示例配置中,点击bD
将导致 nnn 跳转到~/Downloads
。但所有这些都是可选的,nnn 在所有机器上的表现都是一样的。
在终端中获取选定文件[编辑 | 编辑源代码]
要获取在 nnn 中选择的文件列表,可以创建以下别名:
~/.bashrc
alias ncp="cat ${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} | tr '\0' '\n'"
随后可将所选文件导入其他工具。
Indicate depth level within nnn shells[编辑 | 编辑源代码]
If you use !
to spawn a shell in the current directory, it could be nice to add:
~/.bashrc
[ -n "$NNNLVL" ] && PS1="N$NNNLVL $PS1"
To have your prompt indicate that you are within a shell that will return you to nnn when you are done.
This together with #cd on quit (Ctrl-G) becomes a powerful combination.
cd on quit (Ctrl-G)[编辑 | 编辑源代码]
Add the following to your .bashrc
/.zshrc
~/.bashrc or ~/.zshrc
if [ -f /usr/share/nnn/quitcd/quitcd.bash_sh_zsh ]; then source /usr/share/nnn/quitcd/quitcd.bash_sh_zsh fi
And run the n
command instead of nnn
(more precisely the n bash function).
另请参阅 nnn wiki。
添加自己的插件[编辑 | 编辑源代码]
您可以将插件放入 ${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins
中,以运行自己的插件。例如,您可以创建一个可执行的 shell 脚本
${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/git-changes
#!/usr/bin/env sh git log -p -- "$@"
设置环境变量 NNN_PLUG='R:git-changes'
,然后按 ;R
键并选择 git-changes
来触发它,这样就能方便地显示特定文件的 git 更改日志以及代码,以便快速轻松地查看。