From 0c569629bcf1ad98201cef5780c656ba5b06cf73 Mon Sep 17 00:00:00 2001 From: Lockszmith Date: Sat, 18 Jun 2022 14:13:08 -0400 Subject: [PATCH] Refactored to make `zsh` support as seamless as `bash` --- _home/dot_bashrc | 25 ++-------------- _home/dot_sz.shrc | 30 +++++++++++++++++++ _home/dot_sz.shrc.d/21_aliases | 5 ++++ _home/dot_sz.shrc.d/22_editor.aliases | 10 +++---- _home/dot_sz.shrc.d/31_zfs | 2 +- _home/dot_sz.shrc.d/91_keyboard_mappings | 2 +- _home/dot_sz.shrc.d/97_chezmoi_aliases | 2 +- _home/dot_sz.shrc.d/bash.post/10_oh-my-posh | 2 +- .../bash.post/11_persistent.history | 4 +-- _home/dot_sz.shrc.d/zsh.post/10_oh-my-posh | 6 ++++ _home/dot_sz.shrc.d/zsh.pre/00_default | 15 ++++++++++ _home/dot_sz.shrc.d/zsh.pre/21_aliases | 1 + _home/dot_zshrc | 15 ++-------- 13 files changed, 73 insertions(+), 46 deletions(-) create mode 100644 _home/dot_sz.shrc create mode 100644 _home/dot_sz.shrc.d/zsh.post/10_oh-my-posh create mode 100644 _home/dot_sz.shrc.d/zsh.pre/00_default create mode 100644 _home/dot_sz.shrc.d/zsh.pre/21_aliases diff --git a/_home/dot_bashrc b/_home/dot_bashrc index baa6048..afe2ed4 100644 --- a/_home/dot_bashrc +++ b/_home/dot_bashrc @@ -1,27 +1,8 @@ # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples +[ -z ${DBG_SZSHRC} ] || echo "Entered .bashrc" -# If not running interactively, don't do anything -case $- in - *i*) echo "Welcome $USER to $(hostname)";; - *) return;; -esac +[[ -r ~/.sz.shrc ]] && source ~/.sz.shrc -if [ -d ~/.sz.shrc.d ]; then - script_source=("$(find ~/.sz.shrc.d -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).pre")") - script_source+=("$(find ~/.sz.shrc.d -maxdepth 0 -type d)") - script_source+=("$(find ~/.sz.shrc.d -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).post")") - for script_src in ${script_source[@]}; do - scripts=$(find $script_src -maxdepth 1 -type f -not -name "*.off" -not -name "*.swp" | sort) - for script_name in $scripts; do - if [ -r $script_name ]; then - [ -z ${DBG_SZSHRC} ] || echo "Sourcing $script_name..." - . $script_name - fi - done - unset scripts - unset script_name - done - unset script_source -fi +[ -z ${DBG_SZSHRC} ] || echo "Exiting .bashrc" diff --git a/_home/dot_sz.shrc b/_home/dot_sz.shrc new file mode 100644 index 0000000..55d01fd --- /dev/null +++ b/_home/dot_sz.shrc @@ -0,0 +1,30 @@ +# If not running interactively, don't do anything +[ -z ${DBG_SZSHRC} ] || echo "Entered .sz.shrc" + +case $- in + *i*) echo "Welcome $USER to $(hostname)";; + *) return;; +esac + +if [ -d ~/.sz.shrc.d ]; then + script_source=("$(find ~/.sz.shrc.d -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).pre")") + script_source+=("$(find ~/.sz.shrc.d -maxdepth 0 -type d)") + script_source+=("$(find ~/.sz.shrc.d -maxdepth 1 -type d -name "$(ps -p$$ -ho comm).post")") + [ -z ${DBG_SZSHRC} ] || echo "Working with (${script_source[@]})..." + for script_src in ${script_source[@]}; do + scripts=($(find $script_src -maxdepth 1 -type f -not -name "*.off" -not -name "*.swp" | sort)) + #[ -z ${DBG_SZSHRC} ] || echo "Within $script_src, will review (${scripts[@]})..." + for script_name in ${scripts[@]}; do + [ -z ${DBG_SZSHRC} ] || echo "Checking $script_name..." + if [ -r $script_name ]; then + [ -z ${DBG_SZSHRC} ] || echo "Sourcing $script_name..." + . $script_name + fi + done + unset scripts + unset script_name + done + unset script_source +fi + +[ -z ${DBG_SZSHRC} ] || echo "Exiting .sz.shrc" diff --git a/_home/dot_sz.shrc.d/21_aliases b/_home/dot_sz.shrc.d/21_aliases index 2a4a8db..6461d33 100644 --- a/_home/dot_sz.shrc.d/21_aliases +++ b/_home/dot_sz.shrc.d/21_aliases @@ -1,5 +1,10 @@ alias sudo="/usr/bin/sudo " +# some more ls aliases +alias ll='ls -alF' +alias la='ls -A' +alias l='ls -CF' + alias lessr="less --raw-control-chars " alias sz-edshrc="ed ~/.sz.shrc.d ; exec $SHELL" diff --git a/_home/dot_sz.shrc.d/22_editor.aliases b/_home/dot_sz.shrc.d/22_editor.aliases index dc05560..dd5226b 100644 --- a/_home/dot_sz.shrc.d/22_editor.aliases +++ b/_home/dot_sz.shrc.d/22_editor.aliases @@ -1,6 +1,6 @@ -PREFERED_VI=$(type -fP nvim vim | head -1) +PREFERED_VI=$(which-command nvim vim | head -1) if [[ -z "$PREFERED_VI" ]]; then - PREFERED_VI=$(type -fP vi | head -1) + PREFERED_VI=$(which-command vi | head -1) if [[ -z "$PREFERED_VI" ]]; then alias my_vi='eval $EDITOR ' @@ -12,9 +12,9 @@ else fi if [[ -r "$HOME/.config/_my.emacs/spacemacs/emacs.d/init.el" \ - && -n "$(type -fP emacsclient)" \ - && -n "$(type -fP emacs)" \ - && -n "$(type -fP edit-with-spacemacs)" \ + && -n "$(which-command emacsclient)" \ + && -n "$(which-command emacs)" \ + && -n "$(which-command edit-with-spacemacs)" \ ]]; then alias my_editor='edit-with-spacemacs' else diff --git a/_home/dot_sz.shrc.d/31_zfs b/_home/dot_sz.shrc.d/31_zfs index e24d27e..928c93c 100644 --- a/_home/dot_sz.shrc.d/31_zfs +++ b/_home/dot_sz.shrc.d/31_zfs @@ -1,3 +1,3 @@ -if [[ -n "$(type -fP zfs)" ]]; then +if [[ -n "$(which-command zfs)" ]]; then alias zls='sudo zfs list -o name,used,avail,refer,canmount,mounted,mountpoint' fi diff --git a/_home/dot_sz.shrc.d/91_keyboard_mappings b/_home/dot_sz.shrc.d/91_keyboard_mappings index 81f6cd3..6204bf0 100644 --- a/_home/dot_sz.shrc.d/91_keyboard_mappings +++ b/_home/dot_sz.shrc.d/91_keyboard_mappings @@ -1,4 +1,4 @@ -if [[ -n "$(type -fP setxkbmap)" && -n "$DISPLAY" ]]; then +if [[ -n "$(which-command setxkbmap)" && -n "$DISPLAY" ]]; then setxkbmap -option setxkbmap -option caps:escape setxkbmap -option caps:ctrl_modifier diff --git a/_home/dot_sz.shrc.d/97_chezmoi_aliases b/_home/dot_sz.shrc.d/97_chezmoi_aliases index 8bb8423..56cedc2 100644 --- a/_home/dot_sz.shrc.d/97_chezmoi_aliases +++ b/_home/dot_sz.shrc.d/97_chezmoi_aliases @@ -1,4 +1,4 @@ -if [[ -n "$(type -fP chezmoi)" ]]; then +if [[ -n "$(which-command chezmoi)" ]]; then alias cdcz="cd $(chezmoi source-path)" alias czcd="cdcz " diff --git a/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh b/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh index 45b7800..a598361 100644 --- a/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh +++ b/_home/dot_sz.shrc.d/bash.post/10_oh-my-posh @@ -1,4 +1,4 @@ -if [[ -n "$(type -fP oh-my-posh)" && -z "$INSIDE_EMACS" ]]; then +if [[ -n "$(which-command oh-my-posh)" ]]; then OHMYPOSH_CONFIG='' [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="~/.poshtheme.omp.json" eval "$(oh-my-posh init bash --config $OHMYPOSH_CONFIG)" diff --git a/_home/dot_sz.shrc.d/bash.post/11_persistent.history b/_home/dot_sz.shrc.d/bash.post/11_persistent.history index bce26ab..0a5fcde 100644 --- a/_home/dot_sz.shrc.d/bash.post/11_persistent.history +++ b/_home/dot_sz.shrc.d/bash.post/11_persistent.history @@ -4,6 +4,4 @@ export HISTFILESIZE=100000 # big big history shopt -s histappend # append to history, don't overwrite it # Save and reload the history after each command finishes -if ! [[ "$PROMPT_COMMAND" =~ "history -a; history -c; history -r;" ]]; then - export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" -fi +export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" diff --git a/_home/dot_sz.shrc.d/zsh.post/10_oh-my-posh b/_home/dot_sz.shrc.d/zsh.post/10_oh-my-posh new file mode 100644 index 0000000..16ffddd --- /dev/null +++ b/_home/dot_sz.shrc.d/zsh.post/10_oh-my-posh @@ -0,0 +1,6 @@ +if [[ -n "$(which-command oh-my-posh)" ]]; then + OHMYPOSH_CONFIG='' + [[ -r ~/.poshtheme.omp.json ]] && OHMYPOSH_CONFIG="~/.poshtheme.omp.json" + eval "$(oh-my-posh init zsh --config $OHMYPOSH_CONFIG)" + unset OHMYPOSH_CONFIG +fi diff --git a/_home/dot_sz.shrc.d/zsh.pre/00_default b/_home/dot_sz.shrc.d/zsh.pre/00_default new file mode 100644 index 0000000..40a772a --- /dev/null +++ b/_home/dot_sz.shrc.d/zsh.pre/00_default @@ -0,0 +1,15 @@ +# The following lines were added by compinstall + +zstyle ':completion:*' completer _complete _ignored +zstyle :compinstall filename '/mnt/szmedia/USERDATA/home/sz/.zshrc' + +autoload -Uz compinit +compinit +# End of lines added by compinstall +# Lines configured by zsh-newuser-install +HISTFILE=~/.histfile +HISTSIZE=1000 +SAVEHIST=99999 +bindkey -e +# End of lines configured by zsh-newuser-install + diff --git a/_home/dot_sz.shrc.d/zsh.pre/21_aliases b/_home/dot_sz.shrc.d/zsh.pre/21_aliases new file mode 100644 index 0000000..7425be2 --- /dev/null +++ b/_home/dot_sz.shrc.d/zsh.pre/21_aliases @@ -0,0 +1 @@ +alias which_command="whence " diff --git a/_home/dot_zshrc b/_home/dot_zshrc index 60a686e..871f1f1 100644 --- a/_home/dot_zshrc +++ b/_home/dot_zshrc @@ -1,14 +1,5 @@ -# The following lines were added by compinstall +[ -z ${DBG_SZSHRC} ] || echo "Entered .zshrc" -zstyle ':completion:*' completer _complete _ignored -zstyle :compinstall filename '/mnt/szmedia/USERDATA/home/sz/.zshrc' +[[ -r ~/.sz.shrc ]] && source ~/.sz.shrc -autoload -Uz compinit -compinit -# End of lines added by compinstall -# Lines configured by zsh-newuser-install -HISTFILE=~/.histfile -HISTSIZE=1000 -SAVEHIST=99999 -bindkey -e -# End of lines configured by zsh-newuser-install +[ -z ${DBG_SZSHRC} ] || echo "Exiting .zshrc"