From 0cd62c36d72fd43f7ef0904e97656a85ad0b870b Mon Sep 17 00:00:00 2001 From: Christian Baer Date: Tue, 2 Jun 2020 15:59:14 +0200 Subject: [PATCH] Restructured zsh config --- .gitignore | 1 + .zlogin | 2 -- .zsh/.zlogin | 35 +++++++++++++++++++ .zsh/.zshrc | 4 +++ .zsh/lib/{path.zsh => 10-path.zsh} | 3 +- .zsh/lib/{aliases.zsh => 20-aliases.zsh} | 5 ++- .../lib/{completion.zsh => 20-completion.zsh} | 4 +-- .../lib/{correction.zsh => 20-correction.zsh} | 0 .../{directories.zsh => 20-directories.zsh} | 2 +- .zsh/lib/{functions.zsh => 20-functions.zsh} | 2 +- .zsh/lib/{history.zsh => 20-history.zsh} | 0 .../{key_bindings.zsh => 20-key_bindings.zsh} | 0 .zsh/lib/{shortcuts.zsh => 20-shortcuts.zsh} | 0 .../lib/{appearance.zsh => 30-appearance.zsh} | 2 +- .zsh/lib/{colors.zsh => 30-colors.zsh} | 7 ---- .zsh/lib/{misc.zsh => 30-misc.zsh} | 0 .zsh/lib/{prompt.zsh => 30-prompt.zsh} | 2 +- .zsh/lib/{rprompt.zsh => 30-rprompt.zsh} | 0 .zshenv | 7 ++++ .zshrc | 8 ----- 20 files changed, 56 insertions(+), 28 deletions(-) delete mode 100644 .zlogin create mode 100644 .zsh/.zlogin create mode 100644 .zsh/.zshrc rename .zsh/lib/{path.zsh => 10-path.zsh} (95%) rename .zsh/lib/{aliases.zsh => 20-aliases.zsh} (92%) rename .zsh/lib/{completion.zsh => 20-completion.zsh} (97%) rename .zsh/lib/{correction.zsh => 20-correction.zsh} (100%) rename .zsh/lib/{directories.zsh => 20-directories.zsh} (75%) rename .zsh/lib/{functions.zsh => 20-functions.zsh} (50%) rename .zsh/lib/{history.zsh => 20-history.zsh} (100%) rename .zsh/lib/{key_bindings.zsh => 20-key_bindings.zsh} (100%) rename .zsh/lib/{shortcuts.zsh => 20-shortcuts.zsh} (100%) rename .zsh/lib/{appearance.zsh => 30-appearance.zsh} (96%) rename .zsh/lib/{colors.zsh => 30-colors.zsh} (79%) rename .zsh/lib/{misc.zsh => 30-misc.zsh} (100%) rename .zsh/lib/{prompt.zsh => 30-prompt.zsh} (92%) rename .zsh/lib/{rprompt.zsh => 30-rprompt.zsh} (100%) create mode 100644 .zshenv delete mode 100644 .zshrc diff --git a/.gitignore b/.gitignore index b878e6e..a6626e6 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ Thumbs.db *.sublime-* *.log +.zsh/lib/30-extra.zsh diff --git a/.zlogin b/.zlogin deleted file mode 100644 index 2d224a2..0000000 --- a/.zlogin +++ /dev/null @@ -1,2 +0,0 @@ -uname -npsr -uptime diff --git a/.zsh/.zlogin b/.zsh/.zlogin new file mode 100644 index 0000000..6559f1b --- /dev/null +++ b/.zsh/.zlogin @@ -0,0 +1,35 @@ +## $ZDOTDIR/.zlogin - Contains commands that should be executed only in login shells + +# Load config files in $ZSH/lib that for stage 3 +for config_file ($ZDOTDIR/lib/30-*.zsh) source $config_file + +## Run tasks in background +( +#Initalize and compile completion cache +autoload -Uz compinit +compinit + +#Compile startup files + +autoload -Uz zrecompile + +for ((i=1; i <= $#fpath; ++i)); do + dir=$fpath[i] + zwc=${dir:t}.zwc + if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then + continue + fi + files=($dir/*(N-.)) + if [[ -w $dir:h && -n $files ]]; then + files=(${${(M)files%/*/*}#/}) + if ( cd $dir:h && + zrecompile -p -U -z $zwc $files ); then + fpath[i]=$fpath[i].zwc + fi + fi +done +) + +## Print some system info +uname -npsr +uptime diff --git a/.zsh/.zshrc b/.zsh/.zshrc new file mode 100644 index 0000000..feb4d4a --- /dev/null +++ b/.zsh/.zshrc @@ -0,0 +1,4 @@ +## $ZDOTDIR/.zshrc - Should be used to set up aliases, functions, keybindings etc. + +# Load config files in $ZSH/lib that for stage 2 +for config_file ($ZDOTDIR/lib/20-*.zsh) source $config_file diff --git a/.zsh/lib/path.zsh b/.zsh/lib/10-path.zsh similarity index 95% rename from .zsh/lib/path.zsh rename to .zsh/lib/10-path.zsh index 97ccad4..f627cb8 100644 --- a/.zsh/lib/path.zsh +++ b/.zsh/lib/10-path.zsh @@ -14,7 +14,6 @@ _prepath() { _prepath /usr/local/bin /bin /usr/local/sbin # General _prepath /usr/bin /usr/sbin /sbin /Library/Apple/usr/bin # macOS _prepath /usr/sbin /sbin # FreeBSD - -_prepath "$HOME/bin" +_prepath ~/bin unfunction _prepath diff --git a/.zsh/lib/aliases.zsh b/.zsh/lib/20-aliases.zsh similarity index 92% rename from .zsh/lib/aliases.zsh rename to .zsh/lib/20-aliases.zsh index d4c69cb..ccccc18 100644 --- a/.zsh/lib/aliases.zsh +++ b/.zsh/lib/20-aliases.zsh @@ -10,13 +10,12 @@ fi unfunction _exists - alias ls='ls --color=always -h' alias ll='ls -la' alias ...='cd ../..' alias foldersize='du -sh' alias duf='du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done' -alias whois="whois -h whois-servers.net" +alias google='ping -c 10240000 google.com' case `uname` in Darwin) @@ -27,7 +26,6 @@ case `uname` in alias r='open -a' alias sulast='sudo $(history -p !-1)' alias ydl="youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'" - alias google='ping -c 10240000 google.com' alias nmap_localnet='nmap -sP 10.0.3.0/24' ;; Linux) @@ -35,5 +33,6 @@ case `uname` in ;; FreeBSD) # commands for FreeBSD go here + alias stl="sockstat -l" ;; esac diff --git a/.zsh/lib/completion.zsh b/.zsh/lib/20-completion.zsh similarity index 97% rename from .zsh/lib/completion.zsh rename to .zsh/lib/20-completion.zsh index 76fcedb..5ba2d8f 100644 --- a/.zsh/lib/completion.zsh +++ b/.zsh/lib/20-completion.zsh @@ -9,8 +9,8 @@ setopt always_to_end WORDCHARS='' zmodload -i zsh/complist -fpath=(~/.zsh/comp/ $fpath) -fpath=(/usr/local/share/zsh/site-functions/ $fpath) +fpath=($fpath $ZDOTDIR/completions/) +fpath=($fpath /usr/local/share/zsh/site-functions/) ## case-insensitive (all),partial-word and then substring completion if [ "x$CASE_SENSITIVE" = "xtrue" ]; then diff --git a/.zsh/lib/correction.zsh b/.zsh/lib/20-correction.zsh similarity index 100% rename from .zsh/lib/correction.zsh rename to .zsh/lib/20-correction.zsh diff --git a/.zsh/lib/directories.zsh b/.zsh/lib/20-directories.zsh similarity index 75% rename from .zsh/lib/directories.zsh rename to .zsh/lib/20-directories.zsh index 071dbef..9307fe5 100644 --- a/.zsh/lib/directories.zsh +++ b/.zsh/lib/20-directories.zsh @@ -1,4 +1,4 @@ # Changing/making/removing directory setopt auto_name_dirs setopt auto_pushd -setopt pushd_ignore_dups \ No newline at end of file +setopt pushd_ignore_dups diff --git a/.zsh/lib/functions.zsh b/.zsh/lib/20-functions.zsh similarity index 50% rename from .zsh/lib/functions.zsh rename to .zsh/lib/20-functions.zsh index 597741c..3699253 100644 --- a/.zsh/lib/functions.zsh +++ b/.zsh/lib/20-functions.zsh @@ -1,4 +1,4 @@ -fpath+=$ZDOTDIR/functions +fpath=($fpath $ZDOTDIR/functions) autoload extract autoload img2iso diff --git a/.zsh/lib/history.zsh b/.zsh/lib/20-history.zsh similarity index 100% rename from .zsh/lib/history.zsh rename to .zsh/lib/20-history.zsh diff --git a/.zsh/lib/key_bindings.zsh b/.zsh/lib/20-key_bindings.zsh similarity index 100% rename from .zsh/lib/key_bindings.zsh rename to .zsh/lib/20-key_bindings.zsh diff --git a/.zsh/lib/shortcuts.zsh b/.zsh/lib/20-shortcuts.zsh similarity index 100% rename from .zsh/lib/shortcuts.zsh rename to .zsh/lib/20-shortcuts.zsh diff --git a/.zsh/lib/appearance.zsh b/.zsh/lib/30-appearance.zsh similarity index 96% rename from .zsh/lib/appearance.zsh rename to .zsh/lib/30-appearance.zsh index 320c2c1..50e7e7a 100644 --- a/.zsh/lib/appearance.zsh +++ b/.zsh/lib/30-appearance.zsh @@ -23,4 +23,4 @@ else fi # Apply theming defaults -PS1="%n@%m:%~%# " \ No newline at end of file +PS1="%n@%m:%~%# " diff --git a/.zsh/lib/colors.zsh b/.zsh/lib/30-colors.zsh similarity index 79% rename from .zsh/lib/colors.zsh rename to .zsh/lib/30-colors.zsh index 79ac2a5..6df0b44 100644 --- a/.zsh/lib/colors.zsh +++ b/.zsh/lib/30-colors.zsh @@ -16,10 +16,3 @@ for color in {000..255}; do FG[$color]="%{[38;5;${color}m%}" BG[$color]="%{[48;5;${color}m%}" done - -# Show all 256 colors with color number -function spectrum_ls() { - for code in {000..255}; do - print -P -- "$code: %F{$code}Test%f" - done -} \ No newline at end of file diff --git a/.zsh/lib/misc.zsh b/.zsh/lib/30-misc.zsh similarity index 100% rename from .zsh/lib/misc.zsh rename to .zsh/lib/30-misc.zsh diff --git a/.zsh/lib/prompt.zsh b/.zsh/lib/30-prompt.zsh similarity index 92% rename from .zsh/lib/prompt.zsh rename to .zsh/lib/30-prompt.zsh index 4462c7a..0160ab7 100644 --- a/.zsh/lib/prompt.zsh +++ b/.zsh/lib/30-prompt.zsh @@ -12,7 +12,7 @@ fi PROMPT+='%F{yellow}%~%f ' # Change green arrows (⇣⇡) if connection is via ssh -if [[ "${SSH_CLIENT}" ]]; then +if [[ "${SSH_CONNECTION}" ]]; then PROMPT+="%F{green}⇣⇡%f %F{white}〉%f"; else PROMPT+="%F{white}〉%f"; diff --git a/.zsh/lib/rprompt.zsh b/.zsh/lib/30-rprompt.zsh similarity index 100% rename from .zsh/lib/rprompt.zsh rename to .zsh/lib/30-rprompt.zsh diff --git a/.zshenv b/.zshenv new file mode 100644 index 0000000..f24a7fc --- /dev/null +++ b/.zshenv @@ -0,0 +1,7 @@ +## ~/.zshenv - Should contain commands to set the $PATH and other important environment variables + +# Where to look for zsh config +ZDOTDIR=~/.zsh + +# Load config files in $ZSH/lib that for stage 3 +for config_file ($ZDOTDIR/lib/10-*.zsh) source $config_file diff --git a/.zshrc b/.zshrc deleted file mode 100644 index 93613ae..0000000 --- a/.zshrc +++ /dev/null @@ -1,8 +0,0 @@ -ZDOTDIR=~/.zsh - -# Load all of the config files in $ZSH/lib that end in .zsh -for config_file ($ZDOTDIR/lib/*.zsh) source $config_file - -# Load and run compinit -autoload -U compinit -compinit -i