terminal: Add fzf file insertion and zoxide cd key binds
The following is added to all three shells bash, zsh, nushell: Pressing c-t at any time lets you insert a file/dir at the current cursor location using fzf. Same for 'T' in vicmd mode. Pressing alt-c at any time lets you jump to that directory using zoxide, with the zle editor content intact. Same for 'C' in vicmd mode. Zsh implementation from: https://github.com/ajeetdsouza/zoxide/issues/357 Bash implementation: https://github.com/ajeetdsouza/zoxide/issues/516 Nushell implementation taken from: https://github.com/junegunn/fzf/issues/4122 TODO: Nushell fzf mapping has one problem in that it does not quote the selected file in any way. So any file with e.g. a space in it will have to be manually fixed afterwards.
This commit is contained in:
parent
40e8287213
commit
fa7e740249
3 changed files with 101 additions and 14 deletions
|
|
@ -12,16 +12,16 @@ CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}"
|
|||
[ -f "$CONFDIR/sh/alias" ] && source "$CONFDIR/sh/alias"
|
||||
# load additional aliases
|
||||
if [ -d "$CONFDIR/sh/alias.d" ]; then
|
||||
for _alias in "$CONFDIR/sh/alias.d"/*.sh; do
|
||||
. "$_alias"
|
||||
done
|
||||
unset _alias
|
||||
for _alias in "$CONFDIR/sh/alias.d"/*.sh; do
|
||||
. "$_alias"
|
||||
done
|
||||
unset _alias
|
||||
fi
|
||||
if [ -d "$CONFDIR/bash/alias.d" ]; then
|
||||
for _alias in "$CONFDIR/bash/alias.d"/*.sh; do
|
||||
. "$_alias"
|
||||
done
|
||||
unset _alias
|
||||
for _alias in "$CONFDIR/bash/alias.d"/*.sh; do
|
||||
. "$_alias"
|
||||
done
|
||||
unset _alias
|
||||
fi
|
||||
|
||||
alias ls='ls --color=auto'
|
||||
|
|
@ -35,4 +35,30 @@ set -o vi
|
|||
stty time 0
|
||||
bind 'set keyseq-timeout 1'
|
||||
|
||||
# insert files with c-t or T in vicmd mode
|
||||
FZF_CTRL_R_COMMAND="" FZF_ALT_C_COMMAND="" eval "$(fzf --bash)"
|
||||
builtin bind -m vi-command '"T": "\C-z\C-t\C-z"'
|
||||
|
||||
_run-cdi() {
|
||||
# Get the directory from zoxide query
|
||||
local dir=$(zoxide query -i)
|
||||
|
||||
# If no directory is found, clear the line
|
||||
if [[ -z "$dir" ]]; then
|
||||
echo ''
|
||||
return
|
||||
fi
|
||||
|
||||
# Call cd with the directory
|
||||
cd -- "$dir"
|
||||
|
||||
# Return the exit status of cd
|
||||
return $?
|
||||
}
|
||||
# Make the function _run-cdi available
|
||||
# shellcheck disable=SC2016
|
||||
bind -x '"\ec": "`_run-cdi`"'
|
||||
# shellcheck disable=SC2016
|
||||
bind -m vi-command -x '"C": "`_run-cdi`"'
|
||||
|
||||
eval "$(atuin init bash)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue