From 3f5c8a2f9f124c6fb1d6654ced51219ba16a9635 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 1 Nov 2024 15:54:29 +0100 Subject: [PATCH] Enable completion from the middle of the word & cleanup zsh config --- modules/cli/home.nix | 14 +++--- modules/cli/zsh/comp.zsh | 13 +++++ modules/cli/zsh/custom.zsh | 84 ------------------------------- modules/cli/zsh/default.nix | 22 +++++---- modules/cli/zsh/init.zsh | 99 +++++++++++++++++++++++++++++++------ 5 files changed, 117 insertions(+), 115 deletions(-) create mode 100644 modules/cli/zsh/comp.zsh delete mode 100644 modules/cli/zsh/custom.zsh diff --git a/modules/cli/home.nix b/modules/cli/home.nix index 48f6281..f8ea599 100644 --- a/modules/cli/home.nix +++ b/modules/cli/home.nix @@ -1,9 +1,4 @@ -{ - pkgs, - lib, - ... -}: -{ +{pkgs, ...}: { imports = [ ./zsh ./nvim @@ -26,6 +21,12 @@ signByDefault = true; key = "~/.ssh/id_rsa.pub"; }; + # TODO: unstable feature not in my fork yet + # maintenance = { + # enable = false; + # # TODO: figure out a way to specify all repositories in ~/projects & ~/work at run time + # repositories = []; + # }; extraConfig = { gpg.format = "ssh"; gpg.ssh.allowedSignersFile = "~/.ssh/allowed_signers"; @@ -43,7 +44,6 @@ core.hookspath = "/dev/null"; # Break compat with older versions of git (and systems that doesn't support mtime) to have better performances feature.manyFiles = true; - # TODO: enable git maintenance }; userEmail = "zoe.roux@zoriya.dev"; diff --git a/modules/cli/zsh/comp.zsh b/modules/cli/zsh/comp.zsh new file mode 100644 index 0000000..9efe7b9 --- /dev/null +++ b/modules/cli/zsh/comp.zsh @@ -0,0 +1,13 @@ +# used by kubectl plugin & maybe some other oh-my-zsh plugins +export ZSH_CACHE_DIR="$HOME/.cache/zsh"; +mkdir -p "$ZSH_CACHE_DIR/completions" +fpath+="$ZSH_CACHE_DIR/completions" + +# case insensitive completion +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' +# enable completion from the middle of the word (MUST be specified just ofter the case-insensitive completion) +zstyle ':completion:*' matcher-list '+l:|=* r:|=*' +# use LS_COLORS for autocompletion +zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} +# allow manual selection in the completion menu +zstyle ':completion:*:*:*:*:*' menu select diff --git a/modules/cli/zsh/custom.zsh b/modules/cli/zsh/custom.zsh deleted file mode 100644 index ddc01fa..0000000 --- a/modules/cli/zsh/custom.zsh +++ /dev/null @@ -1,84 +0,0 @@ -push() { - if [[ -z "$1" ]]; then - git push - return - fi - git add -A && git commit -m "$*" && git push -} - -git-branch-clear() { - git fetch --prune origin - git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D -} - -nixify() { - if [ ! -e ./.envrc ]; then - echo "use nix" > .envrc - fi - if [[ ! -e shell.nix ]] && [[ ! -e default.nix ]]; then - cat > default.nix <<'EOF' -{pkgs ? import {}}: -pkgs.mkShell { - packages = with pkgs; [ - - ]; -} -EOF - fi - direnv allow -} - -flakify() { - if [ ! -e flake.nix ]; then - nix flake new -t github:nix-community/nix-direnv . - elif [ ! -e .envrc ]; then - echo "use flake" > .envrc - fi - direnv allow -} - -(whence -w run-help | grep -q alias) && unalias run-help -autoload run-help - -# Allow customization per client. -[[ -f ~/.config/zsh/custom.zsh ]] && source ~/.config/zsh/custom.zsh - -dotenv() { - DOTENV=".env" - if [[ $1 == "-f" ]]; then - DOTENV=$2 - shift - shift - fi - - ENV=$(cat $DOTENV | sed '/^#/d' | tr '\n' ' ') - - if [[ -z $* ]]; then - export ${=ENV} - else - (export ${=ENV}; $*) - fi -} - -robot_install() { - robot=$(\where -p robot) - if [[ $? -eq 1 ]]; then - pyt=$(\where -p python3) - if [[ $? -eq 1 ]]; then - nix-shell -p python3 - fi - - python3 -m venv /tmp/robot - source /tmp/robot/bin/activate - pip3 install robotframework RESTinstance - fi -} - -touchp() { - mkdir -p "$(dirname "$1")" && touch "$1" -} - -proxy() { - echo "Proxying port $1 to http://proxy.sdg.moe" - ssh -NR "5000:localhost:$1" ssh.sdg.moe -} diff --git a/modules/cli/zsh/default.nix b/modules/cli/zsh/default.nix index 69fb6e2..69ac810 100644 --- a/modules/cli/zsh/default.nix +++ b/modules/cli/zsh/default.nix @@ -157,8 +157,6 @@ enable = true; autocd = true; autosuggestion.enable = true; - # already handled at system level - enableCompletion = false; syntaxHighlighting.enable = true; dotDir = ".config/zsh"; shellAliases = { @@ -193,6 +191,12 @@ viu = "kitty +kitten icat"; icat = "kitty +kitten icat"; }; + shellGlobalAliases = { + "..." = "../.."; + "...." = "../../.."; + "....." = "../../../.."; + "......" = "../../../../.."; + }; plugins = [ { @@ -205,11 +209,6 @@ src = pkgs.zsh-vi-mode; file = "share/zsh-vi-mode/zsh-vi-mode.zsh"; } - { - name = "custom"; - src = ./.; - file = "./custom.zsh"; - } { name = "sudo"; src = pkgs.oh-my-zsh; @@ -241,14 +240,19 @@ file = "share/oh-my-zsh/plugins/copyfile/copyfile.plugin.zsh"; } ]; - initExtra = builtins.readFile ./init.zsh; - initExtraFirst = '' # Create a new tmux session (with a random name) and attach. if [[ -z "$TMUX" ]]; then exec tmux new-session -s "$(hexdump -n 4 -v -e '/1 "%02X"' /dev/urandom)" fi ''; + initExtraBeforeCompInit = builtins.readFile ./comp.zsh; + initExtra = builtins.readFile ./init.zsh; + + envExtra = '' + # disable /etc/zshrc & co (nixos one is really bad) + setopt no_global_rcs + ''; # zprof.enable = true; diff --git a/modules/cli/zsh/init.zsh b/modules/cli/zsh/init.zsh index dc387ed..2387424 100644 --- a/modules/cli/zsh/init.zsh +++ b/modules/cli/zsh/init.zsh @@ -1,7 +1,3 @@ -export ZSH_CACHE_DIR="$HOME/.cache/zsh"; -mkdir -p "$ZSH_CACHE_DIR/completions" -fpath+="$ZSH_CACHE_DIR/completions" - # This speeds up pasting w/ autosuggest # https://github.com/zsh-users/zsh-autosuggestions/issues/238 pasteinit() { @@ -42,18 +38,91 @@ eval "$(nix-your-shell zsh)" setopt rm_star_silent -# case insensitive completion -zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' -# use LS_COLORS for autocompletion -zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} -# allow manual selection in the completion menu -zstyle ':completion:*:*:*:*:*' menu select - # ctrl-left/right bindkey "^[[1;5C" forward-word bindkey "^[[1;5D" backward-word -alias -g ...='../..' -alias -g ....='../../..' -alias -g .....='../../../..' -alias -g ......='../../../../..' +# Allow customization per client. +[[ -f ~/.config/zsh/custom.zsh ]] && source ~/.config/zsh/custom.zsh + +push() { + if [[ -z "$1" ]]; then + git push + return + fi + git add -A && git commit -m "$*" && git push +} + +git-branch-clear() { + git fetch --prune origin + git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D +} + +nixify() { + if [ ! -e ./.envrc ]; then + echo "use nix" > .envrc + fi + if [[ ! -e shell.nix ]]; then + cat > shell.nix <<'EOF' +{pkgs ? import {}}: +pkgs.mkShell { + packages = with pkgs; [ + + ]; +} +EOF + fi + direnv allow +} + +flakify() { + if [ ! -e flake.nix ]; then + nix flake new -t github:nix-community/nix-direnv . + elif [ ! -e .envrc ]; then + echo "use flake" > .envrc + fi + direnv allow +} + +(whence -w run-help | grep -q alias) && unalias run-help +autoload run-help + +dotenv() { + DOTENV=".env" + if [[ $1 == "-f" ]]; then + DOTENV=$2 + shift + shift + fi + + ENV=$(cat $DOTENV | sed '/^#/d' | tr '\n' ' ') + + if [[ -z $* ]]; then + export ${=ENV} + else + (export ${=ENV}; $*) + fi +} + +robot_install() { + robot=$(\where -p robot) + if [[ $? -eq 1 ]]; then + pyt=$(\where -p python3) + if [[ $? -eq 1 ]]; then + nix-shell -p python3 + fi + + python3 -m venv /tmp/robot + source /tmp/robot/bin/activate + pip3 install robotframework RESTinstance + fi +} + +touchp() { + mkdir -p "$(dirname "$1")" && touch "$1" +} + +proxy() { + echo "Proxying port $1 to http://proxy.sdg.moe" + ssh -NR "5000:localhost:$1" ssh.sdg.moe +}