From be4d690e3297be3375c5a167d1c9e245fee3dd82 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 30 Sep 2024 11:13:10 -0700 Subject: [PATCH] [zsh] Update all init-rc functions --- zsh/func/{init_rc_aliases => init-rc-aliases} | 4 +- zsh/func/init-rc-app-environments | 13 ++++++ zsh/func/init-rc-completion | 46 +++++++++++++++++++ zsh/func/{init_rc_linux => init-rc-linux} | 4 +- zsh/func/init-rc-ls | 27 +++++++++++ zsh/func/init-rc-prompt | 29 ++++++++++++ zsh/func/init-rc-zle | 17 +++++++ .../{init_zsh_history => init-rc-zsh-history} | 4 +- .../{init_zsh_options => init-rc-zsh-options} | 4 +- zsh/func/init_app_environments | 17 ------- zsh/func/init_configure_ls | 30 ------------ zsh/func/init_rc_configure_completion | 41 ----------------- zsh/func/init_rc_configure_prompt | 24 ---------- zsh/func/init_rc_configure_zle | 20 -------- zsh/func/init_rc_tilde_paths | 12 ----- zshrc | 17 ++++--- 16 files changed, 148 insertions(+), 161 deletions(-) rename zsh/func/{init_rc_aliases => init-rc-aliases} (93%) create mode 100644 zsh/func/init-rc-app-environments create mode 100644 zsh/func/init-rc-completion rename zsh/func/{init_rc_linux => init-rc-linux} (83%) create mode 100644 zsh/func/init-rc-ls create mode 100644 zsh/func/init-rc-prompt create mode 100644 zsh/func/init-rc-zle rename zsh/func/{init_zsh_history => init-rc-zsh-history} (86%) rename zsh/func/{init_zsh_options => init-rc-zsh-options} (83%) delete mode 100644 zsh/func/init_app_environments delete mode 100644 zsh/func/init_configure_ls delete mode 100644 zsh/func/init_rc_configure_completion delete mode 100644 zsh/func/init_rc_configure_prompt delete mode 100644 zsh/func/init_rc_configure_zle delete mode 100644 zsh/func/init_rc_tilde_paths diff --git a/zsh/func/init_rc_aliases b/zsh/func/init-rc-aliases similarity index 93% rename from zsh/func/init_rc_aliases rename to zsh/func/init-rc-aliases index 4e16fa8..c19ee7c 100644 --- a/zsh/func/init_rc_aliases +++ b/zsh/func/init-rc-aliases @@ -3,7 +3,7 @@ autoload binary_exists -function init_rc_aliases +function init-rc-aliases { alias j='jobs' alias h='history' @@ -34,4 +34,4 @@ function init_rc_aliases alias -s jar='java -jar' } -init_rc_aliases "$@" +init-rc-aliases "$@" diff --git a/zsh/func/init-rc-app-environments b/zsh/func/init-rc-app-environments new file mode 100644 index 0000000..e5250c3 --- /dev/null +++ b/zsh/func/init-rc-app-environments @@ -0,0 +1,13 @@ +#!/usr/bin/env zsh +# Eryn Wells + +autoload binary_exists + +function init-rc-app-environments +{ + # Default ledger file + local -r ledger_file="$HOME/Documents/Ledger/personal.ledger" + [[ -f "$ledger_file" ]] && export LEDGER_FILE="$ledger_file" +} + +init-rc-app-environments "$@" diff --git a/zsh/func/init-rc-completion b/zsh/func/init-rc-completion new file mode 100644 index 0000000..f73b06c --- /dev/null +++ b/zsh/func/init-rc-completion @@ -0,0 +1,46 @@ +#!/usr/bin/env zsh +# Eryn Wells + +function init-rc-completion +{ + autoload -Uz compinit + compinit + + # Cache completions + zstyle ':completion::complete:*' use-cache 1 + zstyle ':completion::complete:*' cache-path ~/.zsh/cache + + # Make ls show completion list in color. + # See also: https://github.com/ohmyzsh/ohmyzsh/issues/6060 + if [[ -n "$LS_COLORS" ]]; then + zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} + else + zstyle ':completion:*:default' list-colors \ + 'di=34' 'ln=35' 'so=32' 'pi=33' 'ex=31' 'bd=34;46' 'cd=34;43' 'su=30;41' \ + 'sg=30;46' 'tw=30;42' 'ow=30;43' + fi + + # For rm, cp, and mv don't complete if file is on the line already + zstyle ':completion:*:rm:*' ignore-line yes + zstyle ':completion:*:cp:*' ignore-line yes + zstyle ':completion:*:mv:*' ignore-line yes + + # Remove trailing slashes in directory arguments + zstyle ':completion:*' squeeze-slashes true + + # Never select parent directory + zstyle ':completion:*:cd:*' ignore-parents parent pwd + + # Expand partial paths + zstyle ':completion:*' expand 'yes' + + # Show a pretty menu of killable processes + zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' + zstyle ':completion:*:*:kill:*' menu yes select + + # Complete man pages by section + zstyle ':completion:*:manuals' separate-sections true + zstyle ':completion:*:manuals.*' insert-sections true +} + +init-rc-completion "$@" diff --git a/zsh/func/init_rc_linux b/zsh/func/init-rc-linux similarity index 83% rename from zsh/func/init_rc_linux rename to zsh/func/init-rc-linux index d756389..1f01355 100644 --- a/zsh/func/init_rc_linux +++ b/zsh/func/init-rc-linux @@ -1,11 +1,11 @@ #!/usr/bin/env zsh # Eryn Wells -function init_rc_linux +function init-rc-linux { alias iptls='sudo iptables --line-numbers -nv -L' alias ip6tls='sudo ip6tables --line-numbers -nv -L' alias rlx="xrdb $HOME/.Xdefaults" } -init_rc_linux "$@" +init-rc-linux "$@" diff --git a/zsh/func/init-rc-ls b/zsh/func/init-rc-ls new file mode 100644 index 0000000..0ae4e3b --- /dev/null +++ b/zsh/func/init-rc-ls @@ -0,0 +1,27 @@ +#!/usr/bin/env zsh +# Eryn Wells + +function init-rc-ls +{ + local ls_options='--color=auto' + alias ls="ls $ls_options" + alias la="ls -A $ls_options" + alias ll="ls -l $ls_options" + alias l.="ls -d $ls_options .*" + + local dircolors_bin=$(whence -p dircolors || whence -p gdircolors) + if [[ -n "$dircolors_bin" ]]; then + local dircolors_config + if [[ -f "$HOME/.dircolors/$SYS.cfg" ]]; then + dircolors_file="$HOME/.dircolors/$SYS.cfg" + else + dircolors_file="$HOME/.dircolors/default.cfg" + fi + + if [[ -f "$dircolors_config" ]]; then + eval $($dircolors_bin $dircolors_config) + fi + fi +} + +init-rc-ls "$@" diff --git a/zsh/func/init-rc-prompt b/zsh/func/init-rc-prompt new file mode 100644 index 0000000..98f3ed9 --- /dev/null +++ b/zsh/func/init-rc-prompt @@ -0,0 +1,29 @@ +#!/usr/bin/env zsh +# Eryn Wells + +function init-rc-prompt +{ + local theme=loquacious + + autoload -U add-zsh-hook + autoload -Uz vcs_info + + zstyle ':vcs_info:*' disable p4 bzr cdv darcs mtn svk tla cvs svn + zstyle ':vcs_info:*' enable git + zstyle ':vcs_info:git:general:*' formats '%b' + zstyle ':vcs_info:git-svn:general:*' formats '%b' + + # Export the current Git branch before every prompt. + function _export-gitbranch { + vcs_info general + export gitbranch=${vcs_info_msg_0_} + } + + add-zsh-hook precmd _export-gitbranch + + autoload -U promptinit + promptinit + prompt $theme +} + +init-rc-prompt "$@" diff --git a/zsh/func/init-rc-zle b/zsh/func/init-rc-zle new file mode 100644 index 0000000..37e79e9 --- /dev/null +++ b/zsh/func/init-rc-zle @@ -0,0 +1,17 @@ +#!/usr/bin/env zsh +# Eryn Wells + +function init-rc-zle +{ + case "${ERYN_ZLE_MODE:-emacs}" in + vim) + bindkey -v + zle -A .backward-delete-char vi-backward-delete-char + ;; + emacs) + bindkey -e + ;; + esac +} + +init-rc-zle "$@" diff --git a/zsh/func/init_zsh_history b/zsh/func/init-rc-zsh-history similarity index 86% rename from zsh/func/init_zsh_history rename to zsh/func/init-rc-zsh-history index ad07940..31d021f 100644 --- a/zsh/func/init_zsh_history +++ b/zsh/func/init-rc-zsh-history @@ -1,7 +1,7 @@ #!/usr/bin/env zsh # Eryn Wells -function init_zsh_history +function init-rc-zsh-history { setopt \ APPEND_HISTORY \ @@ -18,4 +18,4 @@ function init_zsh_history HISTFILE="$HOME/.zhistory" } -init_zsh_history "$@" +init-rc-zsh-history "$@" diff --git a/zsh/func/init_zsh_options b/zsh/func/init-rc-zsh-options similarity index 83% rename from zsh/func/init_zsh_options rename to zsh/func/init-rc-zsh-options index 127f842..8240abb 100644 --- a/zsh/func/init_zsh_options +++ b/zsh/func/init-rc-zsh-options @@ -1,7 +1,7 @@ #!/usr/bin/env zsh # Eryn Wells -function init_zsh_options +function init-rc-zsh-options { # Report seconds since shell was invoked in milliseconds typeset -F SECONDS @@ -13,4 +13,4 @@ function init_zsh_options COMPLETE_IN_WORD } -init_zsh_options "$@" +init-rc-zsh-options "$@" diff --git a/zsh/func/init_app_environments b/zsh/func/init_app_environments deleted file mode 100644 index dbd7a51..0000000 --- a/zsh/func/init_app_environments +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env zsh -# Eryn Wells - -autoload binary_exists - -function init_app_environments -{ - # NetHack options - # use color in the terminal - binary_exists nethack && export NETHACKOPTIONS="color" - - # Default ledger file - local ledgerFile="$HOME/Documents/Ledger/personal.ledger" - [[ -e "$ledgerFile" ]] && LEDGER_FILE="$ledgerFile" -} - -init_app_environments "$@" diff --git a/zsh/func/init_configure_ls b/zsh/func/init_configure_ls deleted file mode 100644 index 1808574..0000000 --- a/zsh/func/init_configure_ls +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env zsh -# Eryn Wells - -local system_ls=`which ls` -local has_gnu_ls -local ls_options - -if $system_ls --version 2>&1 | grep GNU 1>/dev/null; then - has_gnu_ls=1 - ls_options='--color=auto' -else - has_gnu_ls=0 - ls_options='-G' -fi - -alias ls="$system_ls $ls_options" -alias la="$system_ls -A $ls_options" -alias ll="$system_ls -l $ls_options" -alias l.="$system_ls -d $ls_options .*" - -local dircolors_bin=`whence -p dircolors || whence -p gdircolors` -if [[ $has_gnu_ls -eq 1 && -n "$dircolors_bin" ]]; then - if [[ -e "$HOME/.dircolors/$SYS.cfg" ]]; then - dircolors="$HOME/.dircolors/$SYS.cfg" - else - dircolors="$HOME/.dircolors/default.cfg" - fi - - eval `$dircolors_bin $dircolors` -fi diff --git a/zsh/func/init_rc_configure_completion b/zsh/func/init_rc_configure_completion deleted file mode 100644 index 5b378fa..0000000 --- a/zsh/func/init_rc_configure_completion +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env zsh -# Eryn Wells - -autoload -Uz compinit -compinit - -# Cache completions -zstyle ':completion::complete:*' use-cache 1 -zstyle ':completion::complete:*' cache-path ~/.zsh/cache - -# Make ls show completion list in color. -# See also: https://github.com/ohmyzsh/ohmyzsh/issues/6060 -if [[ -n "$LS_COLORS" ]]; then - zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} -else - zstyle ':completion:*:default' list-colors \ - 'di=34' 'ln=35' 'so=32' 'pi=33' 'ex=31' 'bd=34;46' 'cd=34;43' 'su=30;41' \ - 'sg=30;46' 'tw=30;42' 'ow=30;43' -fi - -# For rm, cp, and mv don't complete if file is on the line already -zstyle ':completion:*:rm:*' ignore-line yes -zstyle ':completion:*:cp:*' ignore-line yes -zstyle ':completion:*:mv:*' ignore-line yes - -# Remove trailing slashes in directory arguments -zstyle ':completion:*' squeeze-slashes true - -# Never select parent directory -zstyle ':completion:*:cd:*' ignore-parents parent pwd - -# Expand partial paths -zstyle ':completion:*' expand 'yes' - -# Show a pretty menu of killable processes -zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' -zstyle ':completion:*:*:kill:*' menu yes select - -# Complete man pages by section -zstyle ':completion:*:manuals' separate-sections true -zstyle ':completion:*:manuals.*' insert-sections true diff --git a/zsh/func/init_rc_configure_prompt b/zsh/func/init_rc_configure_prompt deleted file mode 100644 index 669bbd4..0000000 --- a/zsh/func/init_rc_configure_prompt +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env zsh -# Eryn Wells - -local theme=loquacious - -autoload -U add-zsh-hook -autoload -Uz vcs_info - -zstyle ':vcs_info:*' disable p4 bzr cdv darcs mtn svk tla cvs svn -zstyle ':vcs_info:*' enable git -zstyle ':vcs_info:git:general:*' formats '%b' -zstyle ':vcs_info:git-svn:general:*' formats '%b' - -# Export the current Git branch before every prompt. -function export_gitbranch { - vcs_info general - export gitbranch=${vcs_info_msg_0_} -} - -add-zsh-hook precmd export_gitbranch - -autoload -U promptinit -promptinit -prompt $theme diff --git a/zsh/func/init_rc_configure_zle b/zsh/func/init_rc_configure_zle deleted file mode 100644 index f4fc1f1..0000000 --- a/zsh/func/init_rc_configure_zle +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env zsh -# Eryn Wells - -local mode=emacs - -if [[ -z "$mode" ]]; then - mode=emacs -fi - -function configure_zle_emacs { } -function configure_zle_vim { } - -if [[ $mode == 'vim' ]]; then - bindkey -v - configure_zle_vim - zle -A .backward-delete-char vi-backward-delete-char -elif [[ $mode == 'emacs' ]]; then - bindkey -e - configure_zle_emacs -fi diff --git a/zsh/func/init_rc_tilde_paths b/zsh/func/init_rc_tilde_paths deleted file mode 100644 index ba26585..0000000 --- a/zsh/func/init_rc_tilde_paths +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env zsh -# Eryn Wells - -for x in "$HOME/Code" "$HOME/Documents/Code"; do - if [[ ! -d "$x" ]]; then - continue - fi - export c="$x" - break -done - -export dd="$HOME/Library/Developer/Xcode/DerivedData" diff --git a/zshrc b/zshrc index ce0e2c1..8f70595 100644 --- a/zshrc +++ b/zshrc @@ -2,15 +2,14 @@ zsh_init_rc_functions=( \ init_rc_fpath_darwin \ - init_rc_aliases \ - init_configure_ls \ - init_rc_tilde_paths \ - init_rc_configure_prompt \ - init_rc_configure_zle \ - init_rc_configure_completion \ - init_zsh_options \ - init_zsh_history \ - init_app_environments \ + init-rc-aliases \ + init-rc-ls \ + init-rc-prompt \ + init-rc-zle \ + init-rc-completion \ + init-rc-zsh-options \ + init-rc-zsh-history \ + init-rc-app-environments \ init-rc-$SYS \ )