31个版本 (9个重大更改)
| 0.9.2 | 2022年8月23日 |
|---|---|
| 0.9.1 | 2022年5月20日 |
| 0.9.0 | 2022年3月29日 |
| 0.3.5 | 2021年12月23日 |
#765 在 文件系统
每月102 次下载
2MB
1K SLoC
ctrlg ⌨️
按下 ctrl + g 使用模糊查找器在项目之间跳转
演示使用了tmux集成以实现浮动窗口和lighthaus终端主题。
Ctrlg是一个工具,用于使用模糊查找器快速切换到另一个目录。如果启用(通过将$CTRLG_TMUX设置为true),则ctrlg可以将tmux会话中当前窗口的所有分栏cd到选定的目录。按下ctrl + g进行模糊查找目录,这些目录由glob模式配置。
默认情况下,仅搜索~/git/*。要更改此设置或添加其他要搜索的目录,请参阅配置。
安装
使用Cargo
cargo install ctrlg
cargo可以通过rustup.rs安装。
使用安装脚本
不要以root或sudo身份运行,如果需要,脚本将请求sudo。
bash -c 'bash <(curl --proto "=https" --tlsv1.2 -sSf https://raw.githubusercontent.com/mrjones2014/ctrlg/master/install.bash)'
手动
- 从最新GitHub发行版下载适合您系统的相应二进制文件
- 重命名二进制文件为
ctrlg - 通过
chmod +x ctrlg使二进制文件可执行 - 将二进制文件放在您的
$PATH上的任何位置,例如/usr/local/bin/ctrlg
从源代码构建和安装
需要cargo
git clone git@github.com:mrjones2014/ctrlg.git
cd ctrlg
cargo install --path .
Shell插件
一旦安装了CLI,您需要根据您的shell设置快捷键。或者,您可以在运行init脚本之前将默认快捷键禁用,通过将$CTRLG_NOBIND设置为true,然后设置自己的快捷键以调用_ctrlg_search_and_go。
Fish
echo 'ctrlg init fish | source' >> ~/.config/fish/config.fish
Zsh
echo 'eval "$(ctrlg init zsh)"' >> ~/.zshrc
Bash
echo 'eval "$(ctrlg init bash)"' >> ~/.bashrc
Tmux集成
要使ctrlg将cd命令发送到当前tmux窗口的所有分隔窗口,请将环境变量CTRLG_TMUX设置为true。您还可以在tmux浮动窗口中显示模糊查找器,并指定窗口大小,分别使用$CTRLG_TMUX_POPUP和$CTRLG_TMUX_POPUP_ARGS。 $CTRLG_TMUX_POPUP_ARGS可以是tmux popup接受的任何窗口定位或大小参数。$CTRLG_TMUX_POPUP_ARGS的默认值为-w 75% -h 75%。
您还可以定义一个钩子函数,将cd命令发送到当前窗口之外的额外tmux窗口。该函数必须返回一个包含tmux窗口ID的列表。钩子函数是_ctrlg_get_related_panes。
Fish
set CTRLG_TMUX true
set CTRLG_TMUX_POPUP true
# IMPORTANT: quote each argument separately so that the variable is an array
set CTRLG_TMUX_POPUP_ARGS "-w" "75%" "-h" "75%"
Bash或Zsh
export CTRLG_TMUX=true
export CTRLG_TMUX_POPUP=true
# for bash and zsh, quote all arguments together
export CTRLG_TMUX_POPUP_ARGS="-w 75% -h 75%"
快捷键
| 快捷键 | 函数 |
|---|---|
| Enter | cd到所选目录。如果$CTRLG_TMUX为true,则cd命令将发送到当前窗口的所有分隔窗口。 |
| Alt/Option + Enter | cd到所选目录,然后如果已定义,打开$EDITOR。如果使用tmux集成,则仅在该当前活动的tmux窗口中运行$EDITOR命令。 |
| Alt/Option + o | 在不改变shell的cd的情况下打开$EDITOR到所选目录。 |
| Ctrl + o | cd到所选目录仅在当前tmux窗口中,不要将cd命令发送到其他tmux窗口。 |
| Tab | 将选定的目录路径插入到命令行,但不要执行任何操作。仅在Fish和zsh中工作,在bash中,与Ctrl + o相同。 |
| Ctrl + d | 向上滚动预览。 |
| Ctrl + f | 向下滚动预览。 |
配置
ctrlg会在~/.config/ctrlg/config.yml中查找配置文件。以下显示默认配置
# include other configuration files into this configuration file,
# does not search recursively (e.g. you cannot `include` file from
# an already `include`d file). The `include` key is a yaml list
# of file paths to include
include: []
# configure what directories to list in the fuzzy finder
# can be any list of globbing patterns, will only show directories
# not files
search_dirs:
- "~/git/*"
# globbing patterns of files to find for use as preview
# see below for more details on previews
preview_files:
- "README.*"
# enable or disable the preview window
previews: true
# force using or not using `glow` for previews
# this setting takes precedence over `preview_with_bat`
# this represents the default but in an actual
# config file, this should just be `true` or `false`
preview_with_glow: (true if `glow` is installed, false otherwise)
# set the line-wrap width passed to `glow` via `glow -w`
glow_wrap_width: 80
# force using or not using `bat` for previews
# this represents the default but in an actual
# config file, this should just be `true` or `false`
preview_with_bat: (true if `bat` is installed and `glow` is NOT installed, false otherwise)
# force using or not using `exa` for preview fallback when no
# matching `preview_files` are found
# this represents the default but in an actual
# config file, this should just be `true` or `false`
preview_fallback_exa: (true if `exa` is installed, false otherwise)
# enable or disable showing git branch for directories
# which are git repositories
show_git_branch: true
# character to render between the directory name and git branch name
# you can change this to a Nerd Font symbol if you like
# such as git branch symbol:
git_branch_separator: "■"
# customize color scheme
# see section "Color Schemes" below for more details
colors:
# directory name color
dir_name: "cyan"
# git branch color
git_branch: "247,78,39" # this is git's brand orange color
# name of theme to use for `bat`
# see: https://github.com/sharkdp/bat#highlighting-theme
bat_theme: "ansi"
预览
如果启用,预览将通过渲染每个匹配指定preview_filesglobbing模式的目录中的第一个文件来生成。如果找到匹配的文件,默认情况下,如果已安装bat,则使用bat渲染,否则使用cat。您可以使用preview_with_bat选项强制使用或不使用bat。您可以通过设置空globbing模式列表来默认使用回退而不是渲染文件,例如:preview_files: []。
如果没有找到匹配的预览文件,则使用目录列表作为预览。默认情况下,如果已安装exa,则使用exa列出目录内容,否则使用ls。您可以使用preview_fallback_exa选项强制使用或不使用exa作为回退预览。
颜色方案
配置文件中的颜色可以指定为命名颜色、对应于xterm-256颜色代码的单个整数,或整数的RGB三元组(例如255,255,255)。如果指定了无效的颜色(例如,如果您使用小数而不是整数,或使用无效的命名颜色),则默认为白色。为了使xterm-256或RGB颜色正常工作,它必须由您的终端仿真器支持。我推荐Kitty。
命名颜色如下
"black""red""green""yellow""blue""purple""cyan""white"
依赖项
~26–42MB
~774K SLoC