From 944edc4385e8aad92e18fabc7ff0ba24f42ea9b7 Mon Sep 17 00:00:00 2001 From: ene Date: Wed, 15 Feb 2023 18:23:49 +0100 Subject: Feat(home-manager): Add zsh --- home-manager/zsh/config/custom_cursor.sh | 40 +++++++++ home-manager/zsh/config/zsh-init.sh | 38 ++++++++ home-manager/zsh/config/zsh-prompt.sh | 63 +++++++++++++ home-manager/zsh/default.nix | 148 +++++++++++++++++++++++++++++++ services/default.nix | 1 - services/zsh/custom_cursor.sh | 40 --------- services/zsh/zsh-init.sh | 38 -------- services/zsh/zsh-prompt.sh | 63 ------------- services/zsh/zsh.nix | 130 --------------------------- 9 files changed, 289 insertions(+), 272 deletions(-) create mode 100644 home-manager/zsh/config/custom_cursor.sh create mode 100644 home-manager/zsh/config/zsh-init.sh create mode 100644 home-manager/zsh/config/zsh-prompt.sh create mode 100644 home-manager/zsh/default.nix delete mode 100644 services/zsh/custom_cursor.sh delete mode 100644 services/zsh/zsh-init.sh delete mode 100644 services/zsh/zsh-prompt.sh delete mode 100644 services/zsh/zsh.nix diff --git a/home-manager/zsh/config/custom_cursor.sh b/home-manager/zsh/config/custom_cursor.sh new file mode 100644 index 00000000..9a6da012 --- /dev/null +++ b/home-manager/zsh/config/custom_cursor.sh @@ -0,0 +1,40 @@ +# Change cursor shape for different vi modes. +function zle-keymap-select { + if [[ ${KEYMAP} == vicmd ]] || + [[ $1 = 'block' ]]; then + echo -ne '\e[1 q' + elif [[ ${KEYMAP} == main ]] || + [[ ${KEYMAP} == viins ]] || + [[ ${KEYMAP} = '' ]] || + [[ $1 = 'beam' ]]; then + echo -ne '\e[5 q' + fi +} +zle -N zle-keymap-select + +# ci", ci', ci`, di", etc +autoload -U select-quoted +zle -N select-quoted +for m in visual viopp; do + for c in {a,i}{\',\",\`}; do + bindkey -M $m $c select-quoted + done +done + +# ci{, ci(, ci<, di{, etc +autoload -U select-bracketed +zle -N select-bracketed +for m in visual viopp; do + for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do + bindkey -M $m $c select-bracketed + done +done + +zle-line-init() { + zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere) + echo -ne "\e[5 q" +} +zle -N zle-line-init + +echo -ne '\e[5 q' # Use beam shape cursor on startup. +precmd() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt. diff --git a/home-manager/zsh/config/zsh-init.sh b/home-manager/zsh/config/zsh-init.sh new file mode 100644 index 00000000..bc9af87a --- /dev/null +++ b/home-manager/zsh/config/zsh-init.sh @@ -0,0 +1,38 @@ +# If not running interactively, don't do anything +[[ $- != *i* ]] && return + +# Flex on the ubuntu users +[ "$NVIM" ] || neofetch || hyfetch +#loginctl show-session $XDG_SESSION_ID + +## Enable colors and change prompt: +#autoload -Uz colors && colors +#autoload -Uz compinit && compinit -u +## Edit line in vim buffer ctrl-v +#autoload -Uz edit-command-line; zle -N edit-command-line +## Enter vim buffer from normal mode +#autoload -Uz edit-command-line && zle -N edit-command-line + +## zstyles +#zstyle ':completion:*' menu select +## Auto complete with case insensitivity +#zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' + +#zmodload zsh/complist +#fpath+=/home/dt/.config/zsh/comp +#compinit +#_comp_options+=(globdots) # Include hidden files. +# +## Source configs +#source "${ZDOTDIR}/ali.sh" +#source "${ZDOTDIR}/prompt.sh" +#source "${ZDOTDIR}/hotkeys.sh" +source "./${path_custom_cursor}" +#source ~/.local/lib/shell/lib +# +## Load zsh-syntax-highlighting +#source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh +## Suggest aliases for commands +#source /usr/share/zsh/plugins/zsh-you-should-use/you-should-use.plugin.zsh +# +##eval "$(lua ~/scripts/z.lua --init zsh enhanced)" diff --git a/home-manager/zsh/config/zsh-prompt.sh b/home-manager/zsh/config/zsh-prompt.sh new file mode 100644 index 00000000..1f0f164b --- /dev/null +++ b/home-manager/zsh/config/zsh-prompt.sh @@ -0,0 +1,63 @@ +#vim:ft=zsh +_command_time_preexec() { + timer=${timer:-$SECONDS} +} + +_command_time_precmd() { + PROMPT_TMP_DIR=$(mktemp) + if [ $timer ]; then + ts=$(($SECONDS - $timer)) + tts=$ts + mi=0 + ho=0 + if [ $ts -ge 3 ];then + while [ $ts -ge 60 ];do + ts=$((ts-60)) + mi=$((mi+1)) + done + + while [ $mi -ge 60 ];do + mi=$((mi-60)) + ho=$((ho+1)) + done + + if [ $tts -ge 3600 ];then + out=$(printf '%dh %dm %ds\n' $ho $mi $ts) + elif [ $tts -ge 60 ];then + out=$(printf '%dm %ds\n' $mi $ts) + elif [ $tts -lt 60 ];then + out=$(printf '%ds\n' $ts) + fi + + export psvar[1]="took $(printf '%s ' "$out")" + echo $psvar[1] > $PROMPT_TMP_DIR + fi + + unset timer + unset ts + unset tts + unset mi + unset ho +fi +} + +_command_ro_precmd() { +if ! [ -w $(pwd) ];then + echo " " +fi +} + +preexec_functions+=(_command_time_preexec) +precmd_functions+=(_command_time_precmd) + +blue="14" +red="9" +white="15" +setopt PROMPT_SUBST +export PROMPT='%(?.%F{$blue}.%F{$red})%B%3~%(!. %F{$red}as root %f. )%F{$white}$(if [ -n $PROMPT_TMP_DIR ];then cat $PROMPT_TMP_DIR; rm $PROMPT_TMP_DIR;fi)%f%(?.%F{$blue}.%F{$red})%F{$red}$(_command_ro_precmd)%F{$blue}❯ %b%f' +export RPROMPT='' + +#%(2V.%F{$red}%2v%f$(export psvar[2]="") .) + +# TODO: +# Add git support diff --git a/home-manager/zsh/default.nix b/home-manager/zsh/default.nix new file mode 100644 index 00000000..f694b4a9 --- /dev/null +++ b/home-manager/zsh/default.nix @@ -0,0 +1,148 @@ +{ + config, + pkgs, + ... +}: { + programs.zsh = { + enable = true; + enableAutosuggestions = true; + enableCompletion = true; + enableSyntaxHighlighting = true; + + autocd = true; + + dotDir = ".config/zsh"; + + history = { + extended = true; + ignoreDups = false; + expireDuplicatesFirst = false; + ignoreSpace = false; # TODO I might change that + + path = "${config.xdg.dataHome}/zsh/history"; + save = 9000000; # number of lines to save + keep = 9000000; # number of lines to keep + share = true; # share between sessions + + hostorySubstringSearch = { + enable = true; + searchDownKey = "^[[B"; # DOWN Arrow key + searchUpKey = "^[[A"; # UP Arrow key + }; + }; + + loginExtra = + builtins.readFile ./config/zsh-prompt.sh + + builtins.readFile ./config/custome_cursor + + '' + eval $(ssh-agent -s) > /dev/null # start ssh agent + export ENHANCHED_NEOFETCH="$(pacman -Qn | wc -l) (pacman), $(pacman -Qm | wc -l) (aur), $(($(cargo install --list | wc -l ) / 2)) (cargo)" + '' + + builtins.concatSepList "setopt" [ + "AUTO_CD" + "AUTO_PUSHD" + "CHASE_DOTS" + + "ALWAYS_TO_END" + + "EXTENDED_HISTORY" + "HIST_ALLOW_CLOBBER" + "HIST_VERIFY" + "HIST_FCNTL_LOCK" + + "DVORAK" + "CORRECT" + + "PROMPT_SUBST" + "TRANSIENT_RPROMPT" # maybe? + + "COMBINING_CHARS" + "VI" + ]; + + initExtraFirst = builtins.readFile ./config/zsh-init.sh; + + shellAliases = { + ls = "ls -a --color=auto"; + ll = ". ll"; + pip = "pip --require-virtualenv"; + hisea = "history info | grep"; + + mocp = "mocp -M ${config.xdg.configHome}/moc"; + yarn = "yarn --use-yarnrc ${config.xdg.configHome}/yarn/config"; + }; + sessionVariables = { + # managed by home-manager xdg + # XDG_DATA_HOME = "$HOME/.local/share"; + # XDG_STATE_HOME = "$HOME/.local/state"; + # XDG_CACHE_HOME = "$HOME/.cache"; + # XDG_CONFIG_HOME = "$HOME/.config"; + # XDG_BIN_HOME = "\${HOME}/.local/bin"; + + # HISTSIZE = "9000000"; # This Should already be set by the shell + TIMEFMT = "'$fg[green]%J$reset_color' time: $fg[blue]%*Es$reset_color, cpu: $fg[blue]%P$reset_color"; # no idea what this does or why it is needed + REPORTTIME = "10"; + + PATH = [ + "\${PATH}:/home/dt/repos/shell/scripts" + "/home/dt/.local/bin" + "/home/dt/.local/share/cargo/bin/" + ]; + EDITOR = "nvim"; + IVIEWER = "imv"; + READER = "zathura"; + VISUAL = "nvim"; + CODEEDITOR = "nvim"; + TERMINAL = "alacritty"; + BROWSER = "firefox"; + COLORTERM = "truecolor"; + PAGER = "less -R"; + WM = "river"; + AWMWALLPAPER = "/home/dt/media/pictures/tes/wallpapers-linux_cast/Dedicated_Colorschemes/nord/Abstract-Nord.png"; + + # FUNCNEST for more functions in functions + FUNCNEST = "2000"; + + WALLPAPERDIR = "$HOME/media/pictures/wallpapers/"; + LESS = "R"; + MANPAGER = "less -R --use-color -Dd+r -Du+b"; + LIBVIRT_DEFAULT_URI = "qemu:///system"; + BEMENU_SCALE = "1.5"; + BEMENU_BACKEND = "wayland"; + BEMENU_OPTS = "--fn 'Source Code Pro 10' -c -l 30 -B 1 -W 0.9 --hf #ffffff"; + + # Clean the home dir {{{ + _JAVA_OPTIONS = builtins.concatSep " " [ + ''-Djava.util.prefs.userRoot="${config.xdg.configHome}/java"'' + ''-Djavafx.cachedir="${config.xdg.cacheHome}/openjfx"'' + ]; + GRADLE_USER_HOME = "${config.xdg.dataHome}/gradle"; + CARGO_HOME = "${config.xdg.dataHome}/cargo"; + GNUPGHOME = "${config.xdg.dataHome}/gnupg"; + GOPATH = "${config.xdg.dataHome}/go"; + GTK2_RC_FILES = "${config.xdg.configHome}/gtk-2.0/gtkrc"; + LESSHISFILE = "${config.xdg.cacheHome}/less/history"; + LESSKEYIN = "${config.xdg.configHome}/less/lesskey"; + RUSTUP_HOME = "${config.xdg.dataHome}/rustup"; + NPM_CONFIG_USERCONFIG = "${config.xdg.configHome}/npm/npmrc"; + NUGET_PACKAGES = "${config.xdg.cacheHome}/NuGetPackages"; + PYTHONSTARTUP = "${config.xdg.configHome}/python/pythonrc"; + XAUTHORITY = "${config.xdg.stateHome}/Xauthority"; + COMPDUMPFILE = "${config.xdg.dataHome}/zsh/.zcompdump}"; + IPYTHONDIR = "${config.xdg.configHome}/ipython"; + PARALLEL_HOME = "${config.xdg.configHome}/parallel"; + STACK_XDG = "1"; + # }}} + + # Export Wayland env Vars {{{ + QT_QPA_PLATFORM = "wayland"; + QT_QPA_PLATFORMTHEME = "qt5ct"; # needs qt5ct + CLUTTER_BACKEND = "wayland"; + SDL_VIDEODRIVER = "wayland"; # might brake some things + MOZ_ENABLE_WAYLAND = "1"; + # }}} + }; + }; +} +# vim: ts=2 + diff --git a/services/default.nix b/services/default.nix index 27e5086f..4de96e62 100644 --- a/services/default.nix +++ b/services/default.nix @@ -1,6 +1,5 @@ {config, ...}: { imports = [ - ./zsh/zsh.nix ./printing/printing.nix ./nix/nix.nix ]; diff --git a/services/zsh/custom_cursor.sh b/services/zsh/custom_cursor.sh deleted file mode 100644 index 9a6da012..00000000 --- a/services/zsh/custom_cursor.sh +++ /dev/null @@ -1,40 +0,0 @@ -# Change cursor shape for different vi modes. -function zle-keymap-select { - if [[ ${KEYMAP} == vicmd ]] || - [[ $1 = 'block' ]]; then - echo -ne '\e[1 q' - elif [[ ${KEYMAP} == main ]] || - [[ ${KEYMAP} == viins ]] || - [[ ${KEYMAP} = '' ]] || - [[ $1 = 'beam' ]]; then - echo -ne '\e[5 q' - fi -} -zle -N zle-keymap-select - -# ci", ci', ci`, di", etc -autoload -U select-quoted -zle -N select-quoted -for m in visual viopp; do - for c in {a,i}{\',\",\`}; do - bindkey -M $m $c select-quoted - done -done - -# ci{, ci(, ci<, di{, etc -autoload -U select-bracketed -zle -N select-bracketed -for m in visual viopp; do - for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do - bindkey -M $m $c select-bracketed - done -done - -zle-line-init() { - zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere) - echo -ne "\e[5 q" -} -zle -N zle-line-init - -echo -ne '\e[5 q' # Use beam shape cursor on startup. -precmd() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt. diff --git a/services/zsh/zsh-init.sh b/services/zsh/zsh-init.sh deleted file mode 100644 index bc9af87a..00000000 --- a/services/zsh/zsh-init.sh +++ /dev/null @@ -1,38 +0,0 @@ -# If not running interactively, don't do anything -[[ $- != *i* ]] && return - -# Flex on the ubuntu users -[ "$NVIM" ] || neofetch || hyfetch -#loginctl show-session $XDG_SESSION_ID - -## Enable colors and change prompt: -#autoload -Uz colors && colors -#autoload -Uz compinit && compinit -u -## Edit line in vim buffer ctrl-v -#autoload -Uz edit-command-line; zle -N edit-command-line -## Enter vim buffer from normal mode -#autoload -Uz edit-command-line && zle -N edit-command-line - -## zstyles -#zstyle ':completion:*' menu select -## Auto complete with case insensitivity -#zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' - -#zmodload zsh/complist -#fpath+=/home/dt/.config/zsh/comp -#compinit -#_comp_options+=(globdots) # Include hidden files. -# -## Source configs -#source "${ZDOTDIR}/ali.sh" -#source "${ZDOTDIR}/prompt.sh" -#source "${ZDOTDIR}/hotkeys.sh" -source "./${path_custom_cursor}" -#source ~/.local/lib/shell/lib -# -## Load zsh-syntax-highlighting -#source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh -## Suggest aliases for commands -#source /usr/share/zsh/plugins/zsh-you-should-use/you-should-use.plugin.zsh -# -##eval "$(lua ~/scripts/z.lua --init zsh enhanced)" diff --git a/services/zsh/zsh-prompt.sh b/services/zsh/zsh-prompt.sh deleted file mode 100644 index 1f0f164b..00000000 --- a/services/zsh/zsh-prompt.sh +++ /dev/null @@ -1,63 +0,0 @@ -#vim:ft=zsh -_command_time_preexec() { - timer=${timer:-$SECONDS} -} - -_command_time_precmd() { - PROMPT_TMP_DIR=$(mktemp) - if [ $timer ]; then - ts=$(($SECONDS - $timer)) - tts=$ts - mi=0 - ho=0 - if [ $ts -ge 3 ];then - while [ $ts -ge 60 ];do - ts=$((ts-60)) - mi=$((mi+1)) - done - - while [ $mi -ge 60 ];do - mi=$((mi-60)) - ho=$((ho+1)) - done - - if [ $tts -ge 3600 ];then - out=$(printf '%dh %dm %ds\n' $ho $mi $ts) - elif [ $tts -ge 60 ];then - out=$(printf '%dm %ds\n' $mi $ts) - elif [ $tts -lt 60 ];then - out=$(printf '%ds\n' $ts) - fi - - export psvar[1]="took $(printf '%s ' "$out")" - echo $psvar[1] > $PROMPT_TMP_DIR - fi - - unset timer - unset ts - unset tts - unset mi - unset ho -fi -} - -_command_ro_precmd() { -if ! [ -w $(pwd) ];then - echo " " -fi -} - -preexec_functions+=(_command_time_preexec) -precmd_functions+=(_command_time_precmd) - -blue="14" -red="9" -white="15" -setopt PROMPT_SUBST -export PROMPT='%(?.%F{$blue}.%F{$red})%B%3~%(!. %F{$red}as root %f. )%F{$white}$(if [ -n $PROMPT_TMP_DIR ];then cat $PROMPT_TMP_DIR; rm $PROMPT_TMP_DIR;fi)%f%(?.%F{$blue}.%F{$red})%F{$red}$(_command_ro_precmd)%F{$blue}❯ %b%f' -export RPROMPT='' - -#%(2V.%F{$red}%2v%f$(export psvar[2]="") .) - -# TODO: -# Add git support diff --git a/services/zsh/zsh.nix b/services/zsh/zsh.nix deleted file mode 100644 index b8079fd4..00000000 --- a/services/zsh/zsh.nix +++ /dev/null @@ -1,130 +0,0 @@ -{ - config, - pkgs, - ... -}: let - path_config_cursor = builtins.writeFile ./custom_cursor; -in { - programs.zsh = { - enable = true; - zsh-autoenv = { - enable = true; - }; - syntaxHighlighting = { - enable = true; - }; - shellAliases = { - ls = "ls -a --color=auto"; - ll = ". ll"; - pip = "pip --require-virtualenv"; - hisea = "history info | grep"; - - mocp = "mocp -M \"$XDG_CONFIG_HOME\"/moc"; - yarn = "yarn --use-yarnrc \"$XDG_CONFIG_HOME\"/yarn/config"; - }; - setOptions = [ - "AUTO_CD" - "AUTO_PUSHD" - "CHASE_DOTS" - - "ALWAYS_TO_END" - - "EXTENDED_HISTORY" - "HIST_ALLOW_CLOBBER" - "HIST_VERIFY" - "HIST_FCNTL_LOCK" - - "DVORAK" - "CORRECT" - - "PROMPT_SUBST" - "TRANSIENT_RPROMPT" # maybe? - - "COMBINING_CHARS" - "VI" - ]; - - promptInit = - builtins.readFile ./zsh-prompt.sh; - loginShellInit = '' - eval $(ssh-agent -s) > /dev/null # start ssh agent - export ENHANCHED_NEOFETCH="$(pacman -Qn | wc -l) (pacman), $(pacman -Qm | wc -l) (aur), $(($(cargo install --list | wc -l ) / 2)) (cargo)" - ''; - interactiveShellInit = builtins.readFile ./zsh-init.sh; - histSize = 9999999; - histFile = "$XDG_DATA_HOME/zsh/history"; - autosuggestions = { - enable = true; - }; - }; - - environment = { - variables = { - XDG_DATA_HOME = "$HOME/.local/share"; - XDG_STATE_HOME = "$HOME/.local/state"; - XDG_CACHE_HOME = "$HOME/.cache"; - XDG_CONFIG_HOME = "$HOME/.config"; - XDG_BIN_HOME = "\${HOME}/.local/bin"; - - HISTSIZE = "9000000"; - TIMEFMT = "'$fg[green]%J$reset_color' time: $fg[blue]%*Es$reset_color, cpu: $fg[blue]%P$reset_color"; # no idea what this does or why it is needed - REPORTTIME = "10"; - - PATH = [ - "\${PATH}:/home/dt/repos/shell/scripts" - "/home/dt/.local/bin" - "/home/dt/.local/share/cargo/bin/" - ]; - EDITOR = "nvim"; - IVIEWER = "imv"; - READER = "zathura"; - VISUAL = "nvim"; - CODEEDITOR = "nvim"; - TERMINAL = "alacritty"; - BROWSER = "firefox"; - COLORTERM = "truecolor"; - PAGER = "less -R"; - WM = "river"; - AWMWALLPAPER = "/home/dt/media/pictures/tes/wallpapers-linux_cast/Dedicated_Colorschemes/nord/Abstract-Nord.png"; - - # FUNCNEST for more functions in functions - FUNCNEST = "2000"; - - WALLPAPERDIR = "$HOME/media/pictures/wallpapers/"; - LESS = "R"; - MANPAGER = "less -R --use-color -Dd+r -Du+b"; - LIBVIRT_DEFAULT_URI = "qemu:///system"; - BEMENU_SCALE = "1.5"; - BEMENU_BACKEND = "wayland"; - BEMENU_OPTS = "--fn 'Source Code Pro 10' -c -l 30 -B 1 -W 0.9 --hf #ffffff"; - - # Clean the home dir {{{ - _JAVA_OPTIONS = "-Djava.util.prefs.userRoot=$XDG_CONFIG_HOME/java -Djavafx.cachedir = \"$XDG_CACHE_HOME/openjfx\""; - GRADLE_USER_HOME = "\"$XDG_DATA_HOME\"/gradle"; - CARGO_HOME = "\"$XDG_DATA_HOME\"/cargo"; - GNUPGHOME = "\"$XDG_DATA_HOME\"/gnupg"; - GOPATH = "\"$XDG_DATA_HOME\"/go"; - GTK2_RC_FILES = "\"$XDG_CONFIG_HOME\"/gtk-2.0/gtkrc"; - LESSHISFILE = "\"$XDG_CACHE_HOME\"/less/history"; - LESSKEYIN = "\"$XDG_CONFIG_HOME\"/less/lesskey"; - RUSTUP_HOME = "\"$XDG_DATA_HOME\"/rustup"; - NPM_CONFIG_USERCONFIG = "\"$XDG_CONFIG_HOME\"/npm/npmrc"; - NUGET_PACKAGES = "\"$XDG_CACHE_HOME\"/NuGetPackages"; - PYTHONSTARTUP = "\"$XDG_CONFIG_HOME\"/python/pythonrc"; - XAUTHORITY = "\"$XDG_RUNTIME_DIR\"/Xauthority"; - COMPDUMPFILE = "\"$XDG_DATA_DIR\"/zsh/.zcompdump}"; - IPYTHONDIR = "\"$XDG_CONFIG_HOME\"/ipython"; - PARALLEL_HOME = "\"$XDG_CONFIG_HOME\"/parallel"; - STACK_XDG = "1"; - # }}} - - # Export Wayland env Vars {{{ - QT_QPA_PLATFORM = "wayland"; - QT_QPA_PLATFORMTHEME = "qt5ct"; # needs qt5ct - CLUTTER_BACKEND = "wayland"; - SDL_VIDEODRIVER = "wayland"; # might brake some things - MOZ_ENABLE_WAYLAND = "1"; - # }}} - }; - }; -} -- cgit 1.4.1