diff --git a/.config/shell/aliases b/.config/shell/aliases new file mode 100644 index 0000000..98c18fa --- /dev/null +++ b/.config/shell/aliases @@ -0,0 +1,121 @@ +#!/bin/sh +## Short hand programs (ex: sc = shellcheck) >>> +# use nvim rather than vim if the command exists +alias \ + vim='nvim' \ + vimdiff='nvim -d' + +alias \ + vv="$EDITOR" \ + e="$EDITOR" \ + sedit='sudoedit' \ + +# I do this too much by accident smh my head +alias :q='exit' \ + q='exit' \ + +# rmdir is long +alias \ + rmd='rmdir' \ + rd='rmdir' \ + +alias \ + mkd="mkdir -p" \ + g=git \ + sctl='sudo systemctl' \ + +# <<< +## Program improvements (ex: ls = ls -h) >>> +alias sudo='sudo ' # allow using aliases in sudo commands +alias df='df -h' # Human-readable sizes +alias free='free -m' # Show sizes in MB +alias bc='bc -ql' # Make bc usable for fast math +[ -z "$VIMRUNTIME" ] && + alias glow='glow -p' # force Glow to preview with `less` if not in vim + +# I hate it when I get ghost script instead of git status. this will be removed +alias gs="echo 'you don'\''t really want ghost script, do you?'" + +# tell make to use all cpu cores +alias make='make -j$(nproc)' + +# Colors +alias \ + ls='ls -hN --color=auto --group-directories-first' \ + grep='grep --color=auto' \ + diff='diff --color=auto' \ + pacman='pacman --color=auto' \ + parue='/usr/bin/paru --color=auto --sudoloop --newsonupgrade --pgpfetch --upgrademenu --bottomup --fm nvim' \ + paru='parue --skipreview' \ + +command -v lsd > /dev/null && alias \ + ls=lsd \ + lsd='lsd --group-dirs=first' \ + +# <<< +## Mini short-hand scripts (ex: glone = git clone) >>> +# dotfile management +alias dot='git --git-dir="$HOME/git/dotfiles" --work-tree="$HOME"' +alias d='git --git-dir="$HOME/git/dotfiles" --work-tree="$HOME"' # duplicate for auto-complete + +# quicker shutdown +alias sdn='shutdown now' + +# open a new session called 0, but if there is already a session called 0, connect to it +alias tm='tmux new -As0' + +# List available X displays. Useful for finding what display to export when connected over ssh. +alias lsx='ls /tmp/.X11-unix | tr "X" ":"' + +# Make ydotool actually usable for short things +alias ydotool='(sudo ydotoold &) && sleep 0.05 && sudo ydotool' + +# Update zinit and plugins +alias zup='zinit self-update && zinit update --parallel' + +# Edit config files +alias \ + nvc='(cd ~/.config/nvim/lua/blake && nvim ../../init.lua)' \ + zc='$EDITOR ~/.zshrc' \ + fstab='sudoedit /etc/fstab' \ + hst='$EDITOR $HISTFILE' \ + +# Git cLONE +alias glone="git clone" + +# Docker +alias \ + logs='docker-compose logs --tail=200 -f' \ + dupd='docker-compose up -d' \ + ddwn='docker-compose down' \ + dc='docker-compose' \ + occ='docker exec -u www-data nextcloud php occ' \ + +# file copying with a progress bar +alias cpv="rsync -ah --info=progress2" + +# lists all open ports, along with some other info +alias ls-ports='netstat -tulpn' + +# list all disks and their mount points +alias mnt="mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | grep -E '^/dev/' | sort" + +# backs up list of packages +alias packback='comm -23 <(paru -Qqett | sort) <(paru -Qqg base -g base-devel | sort | uniq) > ~/pkglist.txt' + +# thoroughly reset the terminal +alias rce='reset && clear && exec zsh' + +# find pretty much any file, quickly +alias fds='fd --hidden --exclude /run' + +# smart plug things +SMART_PLUG_IP='192.168.1.250' +alias light='tplink_smartplug.py -t $SMART_PLUG_IP -c' + +# Common ls aliases +alias \ + l=ls \ + la='ls -ah' \ + ll='ls -lh' \ + lla='ls -lah' \ diff --git a/.config/shell/env b/.config/shell/env new file mode 100644 index 0000000..22bfeb5 --- /dev/null +++ b/.config/shell/env @@ -0,0 +1,48 @@ +# Blake's environment variables +# This file should be compatible with standard sh + +# Intelligently set $EDITOR +if command -v nvim > /dev/null;then + export EDITOR=nvim +elif command -v vim > /dev/null;then + export EDITOR=vim +elif command -v vi > /dev/null;then + export EDITOR=vi +fi + +export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}" +export PATH="$PATH:${XDG_DATA_HOME:-$HOME/.local}/bin:$SHELL_CONFIG_DIR/bin" +export SYSTEMD_EDITOR="$EDITOR" + +export LSCOLORS="Gxfxcxdxbxegedabagacad" + +export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh" +# Don't add extra space to the right side of the prompt +export ZLE_RPROMPT_INDENT=0 + +export ZINIT_HOME_DIR="${XDG_DATA_HOME:-$HOME/.local}/share/zinit" + +# Set documents directory (auto set to the repo the file ~/todo points to is in) +# shellcheck disable=SC2155 +[ -h ~/todo ] && export DOCS_DIR="$(git -C "$(dirname "$(realpath ~/todo)" 2>&1)" rev-parse --show-toplevel | head -1)" + +WORKING_DIR_SAVE_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/last-working-dir" +# make the dir for the file if needed +! test -d "$(dirname "$WORKING_DIR_SAVE_FILE")" && mkdir -p "$(dirname "$WORKING_DIR_SAVE_FILE")" + +# Plugin setting >>> +# ZSH Vi Mode +export ZVM_VI_HIGHLIGHT_FOREGROUND=#BBC2CF +export ZVM_VI_HIGHLIGHT_BACKGROUND=#515860 +# ZVM_VI_HIGHLIGHT_EXTRASTYLE=bold,underline # bold and underline + +# OMZ Completion +export COMPLETION_WAITING_DOTS=true + +# Powerlevel 10k +export POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD="${POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD:-true}" +export POWERLEVEL9K_INSTANT_PROMPT=quiet +export P10K_CONFIG_LOCATION="$SHELL_CONFIG_DIR/p10k/current" +# <<< + +# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3 diff --git a/.config/shell/updates b/.config/shell/updates new file mode 100755 index 0000000..e369dab --- /dev/null +++ b/.config/shell/updates @@ -0,0 +1,9 @@ +#!/bin/sh +# This file is provided to ensure smooth updates between versions of these +# dotfiles. It is to be run after environment variables are set whenever the +# shell starts, and should be compatible with standard `sh`. + +# [3-18-22] Move Powerlevel 10k config file out of home directory +if [ -f ~/.p10k.zsh ] && ! [ -f "$P10K_CONFIG_LOCATION" ]; then + mv ~/.p10k.zsh "$P10K_CONFIG_LOCATION" +fi diff --git a/.zshrc b/.zshrc index 55e1ac5..d9be272 100644 --- a/.zshrc +++ b/.zshrc @@ -1,260 +1,96 @@ -#!/bin/zsh -# Blake's ZSH config file +# Blake's ZSH configuration file +### Pre-setup >>> +# shellcheck disable=SC1090,SC2296,SC1091,SC2154,SC2015 + +# Helper function to source files. +# Usage: careful_source "file" \ +# "Error message" \ +# $LINENO \ +# [optional: test to run (-f, -x, -e)] \ +# ["optional: operation (source, exec, command or nothing)"] \ +careful_source() { + if test "${4:--f}" "$1"; then + ${5:-source} "$1" + else + echo "$2" >&2 + echo "Line number: $3" >&2 + fi +} + +# for sending error messages from functions and whatnot +error() { + ERROR_CODE="$?" + >&2 echo "(zshrc) An error occurred on line number ${1}" + return $ERROR_CODE +} + +# change cursor to a beam by default +echo -ne '\e[5 q' + +### <<< ### Basic shell configuration >>> ### Environment variables >>> -{ - # Intelligently set $EDITOR - if command -v nvim > /dev/null;then - export EDITOR=nvim - elif command -v vim > /dev/null;then - export EDITOR=vim - elif command -v vi > /dev/null;then - export EDITOR=vi - fi - export SHELL_CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/shell" - export PATH="$PATH:${XDG_DATA_HOME:-$HOME/.local}/bin:$SHELL_CONFIG_DIR/bin" - export SYSTEMD_EDITOR="$EDITOR" +# This has to go here because otherwise we don't know where the config files are :| +export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}" - export LSCOLORS="Gxfxcxdxbxegedabagacad" - export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh" +# source the environment variable file +${SKIP_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/env" \ + "Error: could not locate env file. Things could be messed up. Check that \$SHELL_CONFIG_DIR/env exists." $LINENO - export ZINIT_HOME_DIR="${XDG_DATA_HOME:-$HOME/.local}/share/zinit" - - # Set documents directory (auto set to the repo the file ~/todo points to is in) - [ -h ~/todo ] && export DOCS_DIR="$(git -C "$(dirname "$(realpath ~/todo)" 2>&1)" rev-parse --show-toplevel | head -1)" - - # Don't add extra space to the right side of the prompt - ZLE_RPROMPT_INDENT=0 - - WORKING_DIR_SAVE_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/last-working-dir" - # make the dir for the file if needed - ! test -d "$(dirname "$WORKING_DIR_SAVE_FILE")" && mkdir -p "$(dirname "$WORKING_DIR_SAVE_FILE")" - - # (I know this shouldn't go here, but I needed it to happen early) - # change cursor to beam by default - echo -ne '\e[5 q' - - # Plugin setting >>> - { - # ZSH Vi Mode - ZVM_VI_HIGHLIGHT_FOREGROUND=#BBC2CF - ZVM_VI_HIGHLIGHT_BACKGROUND=#515860 - # ZVM_VI_HIGHLIGHT_EXTRASTYLE=bold,underline # bold and underline - - # OMZ Completion - COMPLETION_WAITING_DOTS=true - } - # <<< - - # optionally source an external environment variable file - [ -f "$SHELL_CONFIG_DIR/shell/envrc" ] && source "$SHELL_CONFIG_DIR/shell/envrc" -} # <<< ### Aliases >>> -{ - ## Short hand programs (ex: sc = shellcheck) >>> - # use nvim rather than vim if the command exists - alias \ - vim='nvim' \ - vimdiff='nvim -d' - - alias \ - vv="$EDITOR" \ - e="$EDITOR" \ - sedit='sudoedit' \ - - # I do this too much by accident smh my head - alias :q='exit' \ - q='exit' \ - - # rmdir is long - alias \ - rmd='rmdir' \ - rd='rmdir' \ - - alias \ - mkd="mkdir -p" \ - g=git \ - sctl='sudo systemctl' \ - - # <<< - ## Program improvements (ex: ls = ls -h) >>> - alias sudo='sudo ' # allow using aliases in sudo commands - alias df='df -h' # Human-readable sizes - alias free='free -m' # Show sizes in MB - alias bc='bc -ql' # Make bc usable for fast math - [ -z "$VIMRUNTIME" ] && - alias glow='glow -p' # force Glow to preview with `less` if not in vim - - # I hate it when I get ghost script instead of git status. this will be removed - alias gs="echo 'you don'\''t really want ghost script, do you?'" - - # tell make to use all cpu cores - alias make='make -j$(nproc)' - - # Colors - alias \ - ls='ls -hN --color=auto --group-directories-first' \ - grep='grep --color=auto' \ - diff='diff --color=auto' \ - pacman='pacman --color=auto' \ - parue='/usr/bin/paru --color=auto --sudoloop --newsonupgrade --pgpfetch --upgrademenu --bottomup --fm nvim' \ - paru='parue --skipreview' \ - - command -v lsd > /dev/null && alias \ - ls=lsd \ - lsd='lsd --group-dirs=first' \ - - # <<< - ## Mini short-hand scripts (ex: glone = git clone) >>> - # dotfile management - alias dot='git --git-dir="$HOME/git/dotfiles" --work-tree="$HOME"' - alias d='git --git-dir="$HOME/git/dotfiles" --work-tree="$HOME"' # duplicate for auto-complete - - # quicker shutdown - alias sdn='shutdown now' - - # open a new session called 0, but if there is already a session called 0, connect to it - alias tm='tmux new -As0' - - # List available X displays. Useful for finding what display to export when connected over ssh. - alias lsx='ls /tmp/.X11-unix | tr "X" ":"' - - # Make ydotool actually usable for short things - alias ydotool='(sudo ydotoold &) && sleep 0.05 && sudo ydotool' - - # Update zinit and plugins - alias zup='zinit self-update && zinit update --parallel' - - # Edit config files - alias \ - nvc='(cd ~/.config/nvim/lua/blake && nvim ../../init.lua)' \ - zc='$EDITOR ~/.zshrc' \ - fstab='sudoedit /etc/fstab' \ - hst='$EDITOR $HISTFILE' \ - - # Git cLONE - alias glone="git clone" - - # Docker - alias \ - logs='docker-compose logs --tail=200 -f' \ - dupd='docker-compose up -d' \ - ddwn='docker-compose down' \ - dc='docker-compose' \ - occ='docker exec -u www-data nextcloud php occ' \ - - # file copying with a progress bar - alias cpv="rsync -ah --info=progress2" - - # lists all open ports, along with some other info - alias ls-ports='netstat -tulpn' - - # list all disks and their mount points - alias mnt="mount | awk -F' ' '{ printf \"%s\t%s\n\",\$1,\$3; }' | column -t | grep -E '^/dev/' | sort" - - # backs up list of packages - alias packback='comm -23 <(paru -Qqett | sort) <(paru -Qqg base -g base-devel | sort | uniq) > ~/pkglist.txt' - - # thoroughly reset the terminal - alias rce='reset && clear && exec zsh' - - # find pretty much any file, quickly - alias fds='fd --hidden --exclude /run' - - # smart plug things - SMART_PLUG_IP='192.168.1.250' - alias light='tplink_smartplug.py -t $SMART_PLUG_IP -c' - - # Common ls aliases - alias \ - l=ls \ - la='ls -ah' \ - ll='ls -lh' \ - lla='ls -lah' \ - - # <<< - # optionally source an external alias file - [ -f "$SHELL_CONFIG_DIR/shell/aliasrc" ] && source "$SHELL_CONFIG_DIR/shell/aliasrc" -} - -# # TODO: remove all aliases that refrence programs which do not exist >>> -# alias fdsa=not_an_alias # test alias -# alias what='which ' # this will return 0 if something we give it cannot be executed -# validate_alias() { -# what "$1" -# } -# # what fdsa -# # may need to use xargs -# for ALIAS in $(alias | cut -d = -f 1);do # assumes you don't have = signs in your alias's names -# echo "validating alias $ALIAS" -# what "$ALIAS" && -# unalias "$ALIAS" && -# echo "alias $ALIAS was removed" -# done -# alias q=exit -# # <<< +# Source the alias file +${SKIP_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/aliases" \ + "Error: could not locate alias file. You may not have any aliases. Check that \$SHELL_CONFIG_DIR points to the right place." $LINENO # <<< ### Functions >>> -{ - # # put all shell functions in their own function that allows them to be updated - # for FN_PATH in "$SHELL_CONFIG_DIR"/functions/*;do - # FN="${FN_PATH##*/}" - # "$FN"() { - # $(source "$FN_PATH") - # } - # - # echo "Declared function $FN" - # echo "Contents of $FN:" - # which "$FN" - # echo - # done +# Organization: functions that are really short should be put here, otherwise +# they should be put in a file located in $SHELL_CONFIG_DIR/functions. If they +# can be converted into a script, they should be. +# +# To make a "function in a file" that fits with my personal spec, simply make a +# file, name it what the function is called, and put the function inside of it +# just like you would if you were writing it here. - # load all functions that are stored in files - fnupdate() { - for FN in "$SHELL_CONFIG_DIR"/functions/*;do - source "$FN" - done - } - fnupdate - - # for sending error messages from functions and whatnot - error() { - ERROR_CODE="$?" - >&2 echo "(zshrc) An error occurred on line number ${1}" - return $ERROR_CODE - } - - # shellcheck disable=SC2016 - mkcd() { - mkdir -p "$1" || error $LINENO - cd "$1" || error $LINENO - } - - # believe it or not, zsh makes for a fine calculator - calc() { - echo $(($*)) - } - - # optionally source an external function file - [ -f "$SHELL_CONFIG_DIR/fnrc" ] && source "$SHELL_CONFIG_DIR/fnrc" +# load all functions that are stored in files +fnupdate() { + for FN in "$SHELL_CONFIG_DIR"/functions/*;do + source "$FN" + done } +fnupdate + +# shellcheck disable=SC2016 +mkcd() { + mkdir -p "$1" || error $LINENO + cd "$1" || error $LINENO +} + +# believe it or not, zsh makes for a fine calculator +calc() { + echo $(($*)) +} + # <<< # <<< +### Apply breaking changes with the update script >>> +${SKIP_UPDATE:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \ + "Error: failed to run update script" $LINENO -x "command" +### <<< ### Plugins >>> { # plugin config >>> # vim-mode cursor # syntax: "[color] [blinking] [style]" see: https://github.com/softmoth/zsh-vim-mode#mode-in-prompt - MODE_CURSOR_VIINS="blinking bar" - MODE_CURSOR_REPLACE="steady bar" - MODE_CURSOR_VICMD="steady block" - MODE_CURSOR_SEARCH="blinking underline" - MODE_CURSOR_VISUAL="steady block" - MODE_CURSOR_VLINE="steady block" + export MODE_CURSOR_VIINS="blinking bar" + export MODE_CURSOR_REPLACE="steady bar" + export MODE_CURSOR_VICMD="steady block" + export MODE_CURSOR_SEARCH="blinking underline" + export MODE_CURSOR_VISUAL="steady block" + export MODE_CURSOR_VLINE="steady block" # <<< # Load zinit >>> { @@ -284,14 +120,19 @@ zdharma-continuum/z-a-bin-gem-node } # <<< - # Plugins to install >>> + # Load plugins >>> + # shellcheck disable=SC2262,SC2016 { # set turbo mode and git clone depth for all plugins alias zinit='ice wait"!0" depth"1";zinit' + # Special history options zinit snippet OMZ::lib/history.zsh - # Some better completion options + # Some better completion options (waiting dots, etc) zinit snippet OMZ::lib/completion.zsh + # Terminal titling + zinit snippet OMZ::lib/termsupport.zsh + # Quality of life zinit load "zsh-users/zsh-autosuggestions" @@ -300,7 +141,7 @@ zinit load "zsh-users/zsh-history-substring-search" zinit load "zsh-users/zsh-completions" - ## Themes + ## Theme # terminal colors if [[ -f "$SHELL_CONFIG_DIR/colors.sh" ]];then # custom colors @@ -309,15 +150,21 @@ # onedark shell colors zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh' fi - # prompt - zinit load "romkatv/powerlevel10k" + # LS Colors zinit ice atclone"dircolors -b ./src/dir_colors > colors.zsh" \ atpull'%atclone' pick"colors.zsh" nocompile'!' \ atload'zstyle ":completion:*" list-colors “${(s.:.)LS_COLORS}”' zinit light arcticicestudio/nord-dircolors - [[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh + # prompt + zinit load "romkatv/powerlevel10k" + if [[ -e "$P10K_CONFIG_LOCATION" ]]; then + source "$P10K_CONFIG_LOCATION" + else + >&2 echo "No p10k theme selected. Please use \`p10k configure\` to make one or select an existing one like this:" + >&2 echo " ln -s $SHELL_CONFIG_DIR/p10k/colorful-angular.p10k.zsh $SHELL_CONFIG_DIR/p10k/current" + fi - # clear plugin options set above + # clear plugin options set at the start of this block unalias zinit # just gonna sneak this in here, too @@ -374,7 +221,7 @@ # Speed up completions zstyle ':completion:*' accept-exact '*(N)' zstyle ':completion:*' use-cache on - zstyle ':completion:*' cache-path $ZSH_CACHE_DIR + zstyle ':completion:*' cache-path "$ZSH_CACHE_DIR" WORDCHARS=${WORDCHARS//\/[&.;]} # Don't consider certain characters part of the word } # <<< @@ -430,115 +277,13 @@ autoload -U compinit colors zcalc compinit -d colors # <<< -### Various manjaro ZSH functions >>> -# Set terminal window and tab/icon title >>> -# usage: title short_tab_title [long_window_title] -# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 -# Fully supports screen and probably most modern xterm and rxvt -# (In screen, only short_tab_title is used) -function title { - emulate -L zsh - setopt prompt_subst - - [[ "$EMACS" == *term* ]] && return - - # if $2 is unset use $1 as default - # if it is set and empty, leave it as is - : ${2=$1} - - case "$TERM" in - xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*) - print -Pn "\e]2;${2:q}\a" # set window name - print -Pn "\e]1;${1:q}\a" # set tab name - ;; - screen*|tmux*) - print -Pn "\ek${1:q}\e\\" # set screen hardstatus - ;; - *) - # Try to use terminfo to set the title - # If the feature is available set title - if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then - echoti tsl - print -Pn "$1" - echoti fsl - fi - ;; - esac -} -# <<< - -ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" # 15 char left truncated PWD -ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~" - -# Runs before showing the prompt >>> -function mzc_termsupport_precmd { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE -} -# <<< - -# Runs before executing the command >>> -function mzc_termsupport_preexec { - [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return - - emulate -L zsh - - # split command into array of arguments - local -a cmdargs - cmdargs=("${(z)2}") # " <- syntax highlighting fix - - # if running fg, extract the command from the job description - if [[ "${cmdargs[1]}" = fg ]]; then - # get the job id from the first argument passed to the fg command - local job_id jobspec="${cmdargs[2]#%}" - # logic based on jobs arguments: - # http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs - # https://www.zsh.org/mla/users/2007/msg00704.html - case "$jobspec" in - <->) # %number argument: - # use the same passed as an argument - job_id=${jobspec} ;; - ""|%|+) # empty, %% or %+ argument: - # use the current job, which appears with a + in $jobstates: - # suspended:+:5071=suspended (tty output) - job_id=${(k)jobstates[(r)*:+:*]} ;; - -) # %- argument: - # use the previous job, which appears with a - in $jobstates: - # suspended:-:6493=suspended (signal) - job_id=${(k)jobstates[(r)*:-:*]} ;; - [?]*) # %?string argument: - # use $jobtexts to match for a job whose command *contains* - job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; - *) # %string argument: - # use $jobtexts to match for a job whose command *starts with* - job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; - esac - - # override preexec function arguments with job command - if [[ -n "${jobtexts[$job_id]}" ]]; then - 1="${jobtexts[$job_id]}" - 2="${jobtexts[$job_id]}" - fi - fi - - # cmd name only, or if this is sudo or ssh, the next cmd - local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%} - local LINE="${2:gs/%/%%}" - - title '$CMD' '%100>...>$LINE%<<' -} -# <<< - -autoload -U add-zsh-hook -add-zsh-hook precmd mzc_termsupport_precmd -add-zsh-hook preexec mzc_termsupport_preexec -# <<< # auto save and load working dir (allow `cd -` on start) >>> # Load the last working directory load_working_dir() { # load the directory (and do validation to make sure it's actually a directory) if test -f "$WORKING_DIR_SAVE_FILE"; then - local PREVIOUS_WORKING_DIR="$(cat "$WORKING_DIR_SAVE_FILE")" + local PREVIOUS_WORKING_DIR + PREVIOUS_WORKING_DIR="$(cat "$WORKING_DIR_SAVE_FILE")" if test -d "$(cat "$WORKING_DIR_SAVE_FILE")"; then cd "$PREVIOUS_WORKING_DIR" || error $LINENO else @@ -560,7 +305,8 @@ save_working_dir() { autoload -U add-zsh-hook add-zsh-hook chpwd save_working_dir -load_working_dir && cd - > /dev/null +# shellchek disable=SC2164 +load_working_dir && cd - > /dev/null || echo -n # Case insensitive globbing (fix for termux) [ -n "$TERMUX_VERSION" ] && (setopt nocaseglob; zstyle ':completion:*' path-completion true) @@ -568,8 +314,8 @@ load_working_dir && cd - > /dev/null # <<< # <<< -# Optionally source the user's customized .zshrc +# Optionally source another zshrc [ -f "$SHELL_CONFIG_DIR/zshrc.local" ] && source "$SHELL_CONFIG_DIR/zshrc.local" || true -# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3 +# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3