feat: add sane delete-backwards

This commit is contained in:
Swarsel 2024-10-15 00:54:18 +02:00
parent ea4e48aa2a
commit 875083a74e
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
2 changed files with 155 additions and 90 deletions

View file

@ -8751,91 +8751,124 @@ zsh is the most convenient shell for me and it happens to be super neat to confi
Here we set some aliases (some of them should be shellApplications instead) as well as some zsh plugins like =fzf-tab=. Here we set some aliases (some of them should be shellApplications instead) as well as some zsh plugins like =fzf-tab=.
#+begin_src nix :tangle profiles/common/home/zsh.nix #+begin_src nix :tangle profiles/common/home/zsh.nix
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
{ {
programs.zsh = { programs.zsh = {
enable = true; enable = true;
shellAliases = lib.recursiveUpdate { shellAliases = lib.recursiveUpdate
hg = "history | grep"; {
hmswitch = "cd ~/.dotfiles; home-manager --flake .#$(whoami)@$(hostname) switch; cd -;"; hg = "history | grep";
nswitch = "cd ~/.dotfiles; sudo nixos-rebuild --flake .#$(hostname) switch; cd -;"; hmswitch = "cd ~/.dotfiles; home-manager --flake .#$(whoami)@$(hostname) switch; cd -;";
nswitch-stay = "cd ~/.dotfiles; git restore flake.lock; sudo nixos-rebuild --flake .#$(hostname) switch; cd -;"; nswitch = "cd ~/.dotfiles; sudo nixos-rebuild --flake .#$(hostname) switch; cd -;";
edithome = "e -w ~/.dotfiles/SwarselSystems.org"; nswitch-stay = "cd ~/.dotfiles; git restore flake.lock; sudo nixos-rebuild --flake .#$(hostname) switch; cd -;";
magit = "emacsclient -nc -e \"(magit-status)\""; edithome = "e -w ~/.dotfiles/SwarselSystems.org";
config = "git --git-dir=$HOME/.cfg/ --work-tree=$HOME"; magit = "emacsclient -nc -e \"(magit-status)\"";
g = "git"; config = "git --git-dir=$HOME/.cfg/ --work-tree=$HOME";
c = "git --git-dir=$HOME/.dotfiles/.git --work-tree=$HOME/.dotfiles/"; g = "git";
passpush = "cd ~/.local/share/password-store; git add .; git commit -m 'pass file changes'; git push; cd -;"; c = "git --git-dir=$HOME/.dotfiles/.git --work-tree=$HOME/.dotfiles/";
passpull = "cd ~/.local/share/password-store; git pull; cd -;"; passpush = "cd ~/.local/share/password-store; git add .; git commit -m 'pass file changes'; git push; cd -;";
hotspot = "nmcli connection up local; nmcli device wifi hotspot;"; passpull = "cd ~/.local/share/password-store; git pull; cd -;";
cd = "z"; hotspot = "nmcli connection up local; nmcli device wifi hotspot;";
cdr = "cd \"$( (find /home/swarsel/Documents/GitHub -maxdepth 1 && echo /home/swarsel/.dotfiles) | fzf )\""; cd = "z";
nix-ldd = "LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH ldd"; cdr = "cd \"$( (find /home/swarsel/Documents/GitHub -maxdepth 1 && echo /home/swarsel/.dotfiles) | fzf )\"";
fs-diff = "sudo mount -o subvol=/ /dev/mapper/cryptroot /mnt ; fs-diff"; nix-ldd = "LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH ldd";
lt = "ls -lath"; fs-diff = "sudo mount -o subvol=/ /dev/mapper/cryptroot /mnt ; fs-diff";
oldshell = "nix shell github:nixos/nixpkgs/\"$1\" \"$2\""; lt = "ls -lath";
} oldshell = "nix shell github:nixos/nixpkgs/\"$1\" \"$2\"";
config.swarselsystems.shellAliases; }
autosuggestion.enable = true; config.swarselsystems.shellAliases;
enableCompletion = true; autosuggestion.enable = true;
syntaxHighlighting.enable = true; enableCompletion = true;
autocd = false; syntaxHighlighting.enable = true;
cdpath = [ autocd = false;
"~/.dotfiles" cdpath = [
# "~/Documents/GitHub" "~/.dotfiles"
]; # "~/Documents/GitHub"
defaultKeymap = "emacs"; ];
dirHashes = { defaultKeymap = "emacs";
dl = "$HOME/Downloads"; dirHashes = {
gh = "$HOME/Documents/GitHub"; dl = "$HOME/Downloads";
}; gh = "$HOME/Documents/GitHub";
history = { };
expireDuplicatesFirst = true; history = {
path = "$HOME/.histfile"; expireDuplicatesFirst = true;
save = 10000; path = "$HOME/.histfile";
size = 10000; save = 10000;
}; size = 10000;
historySubstringSearch.enable = true; };
plugins = [ historySubstringSearch.enable = true;
{ plugins = [
name = "fzf-tab"; {
src = pkgs.zsh-fzf-tab; name = "fzf-tab";
} src = pkgs.zsh-fzf-tab;
]; }
initExtra = '' ];
bindkey "^[[1;5D" backward-word initExtra = ''
bindkey "^[[1;5C" forward-word bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
vterm_printf() { my-backward-delete-word() {
if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then # Copy the global WORDCHARS variable to a local variable. That way any
# Tell tmux to pass the escape sequences through # modifications are scoped to this function only
printf "\ePtmux;\e\e]%s\007\e\\" "$1" local WORDCHARS=$WORDCHARS
elif [ "''${TERM%%-*}" = "screen" ]; then # Use bash string manipulation to remove `:` so our delete will stop at it
# GNU screen (screen, screen-256color, screen-256color-bce) WORDCHARS="''${WORDCHARS//:}"
printf "\eP\e]%s\007\e\\" "$1" # Use bash string manipulation to remove `/` so our delete will stop at it
else WORDCHARS="''${WORDCHARS//\/}"
printf "\e]%s\e\\" "$1" # Use bash string manipulation to remove `.` so our delete will stop at it
fi WORDCHARS="''${WORDCHARS//.}"
} # zle <widget-name> will run an existing widget.
vterm_prompt_end() { zle backward-delete-word
vterm_printf "51;A$(whoami)@$(hostname):$(pwd)" }
} zle -N my-backward-delete-word
setopt PROMPT_SUBST bindkey '^H' my-backward-delete-word
PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
vterm_cmd() { # This will be our `ctrl+alt+w` command
local vterm_elisp my-backward-delete-whole-word() {
vterm_elisp="" # Copy the global WORDCHARS variable to a local variable. That way any
while [ $# -gt 0 ]; do # modifications are scoped to this function only
vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")" local WORDCHARS=$WORDCHARS
shift # Use bash string manipulation to add `:` to WORDCHARS if it's not present
done # already.
vterm_printf "51;E$vterm_elisp" [[ ! $WORDCHARS == *":"* ]] && WORDCHARS="$WORDCHARS"":"
# zle <widget-name> will run that widget.
zle backward-delete-word
}
# `zle -N` will create a new widget that we can use on the command line
zle -N my-backward-delete-whole-word
# bind this new widget to `ctrl+alt+w`
bindkey '^W' my-backward-delete-whole-word
vterm_printf() {
if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then
# Tell tmux to pass the escape sequences through
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
elif [ "''${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf "\eP\e]%s\007\e\\" "$1"
else
printf "\e]%s\e\\" "$1"
fi
}
vterm_prompt_end() {
vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
}
setopt PROMPT_SUBST
PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
vterm_cmd() {
local vterm_elisp
vterm_elisp=""
while [ $# -gt 0 ]; do
vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
shift
done
vterm_printf "51;E$vterm_elisp"
}
'';
};
} }
'';
};
}
#+end_src #+end_src
**** zellij **** zellij

View file

@ -51,10 +51,42 @@
} }
]; ];
initExtra = '' initExtra = ''
bindkey "^[[1;5D" backward-word bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word bindkey "^[[1;5C" forward-word
vterm_printf() { my-backward-delete-word() {
# Copy the global WORDCHARS variable to a local variable. That way any
# modifications are scoped to this function only
local WORDCHARS=$WORDCHARS
# Use bash string manipulation to remove `:` so our delete will stop at it
WORDCHARS="''${WORDCHARS//:}"
# Use bash string manipulation to remove `/` so our delete will stop at it
WORDCHARS="''${WORDCHARS//\/}"
# Use bash string manipulation to remove `.` so our delete will stop at it
WORDCHARS="''${WORDCHARS//.}"
# zle <widget-name> will run an existing widget.
zle backward-delete-word
}
zle -N my-backward-delete-word
bindkey '^H' my-backward-delete-word
# This will be our `ctrl+alt+w` command
my-backward-delete-whole-word() {
# Copy the global WORDCHARS variable to a local variable. That way any
# modifications are scoped to this function only
local WORDCHARS=$WORDCHARS
# Use bash string manipulation to add `:` to WORDCHARS if it's not present
# already.
[[ ! $WORDCHARS == *":"* ]] && WORDCHARS="$WORDCHARS"":"
# zle <widget-name> will run that widget.
zle backward-delete-word
}
# `zle -N` will create a new widget that we can use on the command line
zle -N my-backward-delete-whole-word
# bind this new widget to `ctrl+alt+w`
bindkey '^W' my-backward-delete-whole-word
vterm_printf() {
if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then
# Tell tmux to pass the escape sequences through # Tell tmux to pass the escape sequences through
printf "\ePtmux;\e\e]%s\007\e\\" "$1" printf "\ePtmux;\e\e]%s\007\e\\" "$1"
@ -65,13 +97,13 @@
printf "\e]%s\e\\" "$1" printf "\e]%s\e\\" "$1"
fi fi
} }
vterm_prompt_end() { vterm_prompt_end() {
vterm_printf "51;A$(whoami)@$(hostname):$(pwd)" vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
} }
setopt PROMPT_SUBST setopt PROMPT_SUBST
PROMPT=$PROMPT'%{$(vterm_prompt_end)%}' PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
vterm_cmd() { vterm_cmd() {
local vterm_elisp local vterm_elisp
vterm_elisp="" vterm_elisp=""
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do