More zsh improvements

This commit is contained in:
Thomas Avé 2024-04-24 15:33:53 +02:00
parent e3abbe810c
commit 86eadfdc15
1 changed files with 37 additions and 53 deletions

View File

@ -48,15 +48,8 @@ function cd_to() {
zle reset-prompt
}
function find_local_directories() {
cd_to "$(fd . -t d | fzy -l 20)"
}
function push_local_files() {
emulate -L zsh
zle -I
LBUFFER="${LBUFFER}\"$(fd . -t f | fzy -l 20)\""
zle reset-prompt
function find_local() {
fd . -t $1 | fzy -l 20
}
function find_global() {
@ -88,24 +81,28 @@ function find_global() {
echo $file
}
function find_global_directories() {
cd_to "$(find_global d)"
}
function edit_global_files() {
file="$(find_global f)"
if [ -z "$file" ]; then
return 0
function open_path() {
file_type=$1
search_fn=$2
selection="$($search_fn $file_type)"
if [ "$selection" = "" ]; then
zle reset-prompt
return
fi
cd_to "$(dirname $file)"
nvim "$file"
}
function push_global_directories() {
if [ "$LBUFFER" = "" ]; then
if [ "$file_type" = "d" ]; then
cd_to "$selection"
else
selection=$(realpath "$selection")
cd_to "$(dirname $selection)"
nvim "$selection"
fi
else
emulate -L zsh
zle -I
LBUFFER="${LBUFFER}\"$(find_global d)\""
LBUFFER="${LBUFFER}\"$selection\""
zle reset-prompt
fi
}
function zvm_after_init() {
@ -160,37 +157,24 @@ function zvm_after_init() {
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
fi
zle -N find_global_directories
zle -N push_global_directories
function open_global_path_d() { open_path d find_global }
function open_global_path_f() { open_path f find_global }
function open_local() { open_path f find_local }
zle -N push_local_files
zle -N find_local_directories
zle -N edit_global_files
bindkey "^T" find_global_directories
bindkey -M emacs "^T" find_global_directories
bindkey -M vicmd "^T" find_global_directories
bindkey -M viins "^T" find_global_directories
bindkey "^U" push_global_directories
bindkey -M emacs "^U" push_global_directories
bindkey -M vicmd "^U" push_global_directories
bindkey -M viins "^U" push_global_directories
bindkey "^W" push_local_files
bindkey -M emacs "^W" push_local_files
bindkey -M vicmd "^W" push_local_files
bindkey -M viins "^W" push_local_files
bindkey "^Y" find_local_directories
bindkey -M emacs "^Y" find_local_directories
bindkey -M vicmd "^Y" find_local_directories
bindkey -M viins "^Y" find_local_directories
bindkey "^E" edit_global_files
bindkey -M emacs "^E" edit_global_files
bindkey -M vicmd "^E" edit_global_files
bindkey -M viins "^E" edit_global_files
function register_key() {
zle -N $2
bindkey "^$1" $2
bindkey -M emacs "^$1" $2
bindkey -M vicmd "^$1" $2
bindkey -M viins "^$1" $2
}
register_key "T" open_global_path_d
register_key "E" open_global_path_f
register_key "W" open_local
if [ "$SSH_SESSION_ID" != "" ]; then
mkdir -p /tmp/ssh_sessions