From 960a05363ae9c0b767d57405cfffe9f8a6b021cd Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Sat, 21 Feb 2026 17:11:05 -0500 Subject: refactor(zsh): Restructured common shell files Restructured common shell files to be in a utils directory. Operating System specific files are in the util/OS_NAME/ directories. --- .config/shells/aliasrc | 45 ------------------------------------ .config/shells/colorsrc | 45 ------------------------------------ .config/shells/cpwdrc | 10 -------- .config/shells/dirrc | 9 -------- .config/shells/funcrc | 5 ---- .config/shells/utils/Darwin/aliasrc | 7 ++++++ .config/shells/utils/FreeBSD/aliasrc | 7 ++++++ .config/shells/utils/Linux/aliasrc | 7 ++++++ .config/shells/utils/NetBSD/aliasrc | 7 ++++++ .config/shells/utils/OpenBSD/aliasrc | 7 ++++++ .config/shells/utils/SunOS/aliasrc | 6 +++++ .config/shells/utils/aliasrc | 22 ++++++++++++++++++ .config/shells/utils/colorsrc | 45 ++++++++++++++++++++++++++++++++++++ .config/shells/utils/cpwdrc | 10 ++++++++ .config/shells/utils/dirrc | 9 ++++++++ .config/shells/utils/funcrc | 22 ++++++++++++++++++ .config/shells/zsh/.zshrc | 38 +++++++++++------------------- 17 files changed, 163 insertions(+), 138 deletions(-) delete mode 100755 .config/shells/aliasrc delete mode 100755 .config/shells/colorsrc delete mode 100755 .config/shells/cpwdrc delete mode 100755 .config/shells/dirrc delete mode 100755 .config/shells/funcrc create mode 100755 .config/shells/utils/Darwin/aliasrc create mode 100755 .config/shells/utils/FreeBSD/aliasrc create mode 100755 .config/shells/utils/Linux/aliasrc create mode 100755 .config/shells/utils/NetBSD/aliasrc create mode 100755 .config/shells/utils/OpenBSD/aliasrc create mode 100755 .config/shells/utils/SunOS/aliasrc create mode 100755 .config/shells/utils/aliasrc create mode 100755 .config/shells/utils/colorsrc create mode 100755 .config/shells/utils/cpwdrc create mode 100755 .config/shells/utils/dirrc create mode 100755 .config/shells/utils/funcrc diff --git a/.config/shells/aliasrc b/.config/shells/aliasrc deleted file mode 100755 index bc27955..0000000 --- a/.config/shells/aliasrc +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -# OpenBSD does not have the -G flag -if [[ "$(uname -s)" == "OpenBSD" ]] -then - alias \ - la="ls -Ah" \ - ls="ls -h" \ - l="ls -lAh" -# Linux has --color -elif [[ "$(uname -s)" == "Linux" ]] -then - alias \ - la="ls -Ah --color" \ - ls="ls -h --color" \ - l="ls -lAh --color" -# macOS has -G -else - alias \ - la="ls -AhG" \ - ls="ls -Gh" \ - l="ls -lAhG" -fi - -alias \ - cp="cp -v" \ - rm="rm -v" \ - mv="mv -v" \ - vim="nvim" \ - ..="cd .." \ - ...="cd ../.." \ - .3="cd ../../.." \ - .4="cd ../../../../" \ - .5="cd ../../../../.." \ - zshup="source $HOME/.config/shells/zsh/.zshrc" \ - gc="git clone" \ - gu="git add -u" \ - ga="git commit -a" \ - gp="git push" \ - m="micro" \ - v="nvim" \ - python="python3.10" \ - pip="pip3.10" \ - lf="lfub" - diff --git a/.config/shells/colorsrc b/.config/shells/colorsrc deleted file mode 100755 index 506f67e..0000000 --- a/.config/shells/colorsrc +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -## Reset to normal: \033[0m -NORM="\033[0m" - -## Colors: -BLACK="\033[0;30m" -GRAY="\033[1;30m" -RED="\033[0;31m" -LRED="\033[1;31m" -GREEN="\033[0;32m" -LGREEN="\033[1;32m" -YELLOW="\033[0;33m" -LYELLOW="\033[1;33m" -BLUE="\033[0;34m" -LBLUE="\033[1;34m" -PURPLE="\033[0;35m" -PINK="\033[1;35m" -CYAN="\033[0;36m" -LCYAN="\033[1;36m" -LGRAY="\033[0;37m" -WHITE="\033[1;37m" - -## Backgrounds -BLACKB="\033[0;40m" -REDB="\033[0;41m" -GREENB="\033[0;42m" -YELLOWB="\033[0;43m" -BLUEB="\033[0;44m" -PURPLEB="\033[0;45m" -CYANB="\033[0;46m" -GREYB="\033[0;47m" - -## Attributes: -UNDERLINE="\033[4m" -BOLD="\033[1m" -INVERT="\033[7m" - -## Cursor movements -CUR_UP="\033[1A" -CUR_DN="\033[1B" -CUR_LEFT="\033[1D" -CUR_RIGHT="\033[1C" - -## Start of display (top left) -SOD="\033[1;1f" diff --git a/.config/shells/cpwdrc b/.config/shells/cpwdrc deleted file mode 100755 index d3b9ec4..0000000 --- a/.config/shells/cpwdrc +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -## Collapsed Directory -_collapsed_pwd() { - pwd | perl -pe ' - BEGIN { - binmode STDIN, ":encoding(UTF-8)"; - binmode STDOUT, ":encoding(UTF-8)"; - }; s|^$ENV{HOME}|~|g; s|/([^/.])[^/]*(?=/)|/$1|g; s|/\.([^/])[^/]*(?=/)|/.$1|g -' -} diff --git a/.config/shells/dirrc b/.config/shells/dirrc deleted file mode 100755 index 2815d12..0000000 --- a/.config/shells/dirrc +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -alias \ - b="cd ~/.local/bin" \ - d="cd ~/Documents" \ - bk="cd ~/Documents/Books" \ - dw="cd ~/Downloads" \ - p="cd ~/Documents/Projects" \ - m="cd ~/Documents/musings" \ - c="cd ~/.config" diff --git a/.config/shells/funcrc b/.config/shells/funcrc deleted file mode 100755 index b001f3f..0000000 --- a/.config/shells/funcrc +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -cdl () { cd "${@}" && ls ;} -mkc () { mkdir "${@}" && cd "${@}" ;} - diff --git a/.config/shells/utils/Darwin/aliasrc b/.config/shells/utils/Darwin/aliasrc new file mode 100755 index 0000000..e774b82 --- /dev/null +++ b/.config/shells/utils/Darwin/aliasrc @@ -0,0 +1,7 @@ +#!/bin/sh + +# macOS has -G +alias la="ls -AhG" +alias ls="ls -Gh" +alias l="ls -lAhG" + diff --git a/.config/shells/utils/FreeBSD/aliasrc b/.config/shells/utils/FreeBSD/aliasrc new file mode 100755 index 0000000..e774b82 --- /dev/null +++ b/.config/shells/utils/FreeBSD/aliasrc @@ -0,0 +1,7 @@ +#!/bin/sh + +# macOS has -G +alias la="ls -AhG" +alias ls="ls -Gh" +alias l="ls -lAhG" + diff --git a/.config/shells/utils/Linux/aliasrc b/.config/shells/utils/Linux/aliasrc new file mode 100755 index 0000000..17221ec --- /dev/null +++ b/.config/shells/utils/Linux/aliasrc @@ -0,0 +1,7 @@ +#!/bin/sh + +# Linux has --color +alias la="ls -Ah --color" +alias ls="ls -h --color" +alias l="ls -lAh --color" + diff --git a/.config/shells/utils/NetBSD/aliasrc b/.config/shells/utils/NetBSD/aliasrc new file mode 100755 index 0000000..3558f51 --- /dev/null +++ b/.config/shells/utils/NetBSD/aliasrc @@ -0,0 +1,7 @@ +#!/bin/sh + +# OpenBSD does not have the -G flag +alias la="ls -Ah" +alias ls="ls -h" +alais l="ls -lAh" + diff --git a/.config/shells/utils/OpenBSD/aliasrc b/.config/shells/utils/OpenBSD/aliasrc new file mode 100755 index 0000000..3558f51 --- /dev/null +++ b/.config/shells/utils/OpenBSD/aliasrc @@ -0,0 +1,7 @@ +#!/bin/sh + +# OpenBSD does not have the -G flag +alias la="ls -Ah" +alias ls="ls -h" +alais l="ls -lAh" + diff --git a/.config/shells/utils/SunOS/aliasrc b/.config/shells/utils/SunOS/aliasrc new file mode 100755 index 0000000..3ea7852 --- /dev/null +++ b/.config/shells/utils/SunOS/aliasrc @@ -0,0 +1,6 @@ +#!/bin/sh + +alias la="ls -Ah --color=always" +alias ls="ls -h --color=always" +alias l="ls -lAh --color=always" + diff --git a/.config/shells/utils/aliasrc b/.config/shells/utils/aliasrc new file mode 100755 index 0000000..5e61526 --- /dev/null +++ b/.config/shells/utils/aliasrc @@ -0,0 +1,22 @@ +#!/bin/sh + +alias cp="cp -v" +alias rm="rm -v" +alias mv="mv -v" +alias vim="nvim" +alias ..="cd .." +alias ...="cd ../.." +alias .3="cd ../../.." +alias .4="cd ../../../../" +alias .5="cd ../../../../.." +alias zshup="source $HOME/.config/shells/zsh/.zshrc" +alias gc="git clone" +alias gu="git add -u" +alias ga="git commit -a" +alias gp="git push" +alias m="micro" +alias v="nvim" +alias python="python3.10" +alias pip="pip3.10" +alias lf="lfub" + diff --git a/.config/shells/utils/colorsrc b/.config/shells/utils/colorsrc new file mode 100755 index 0000000..506f67e --- /dev/null +++ b/.config/shells/utils/colorsrc @@ -0,0 +1,45 @@ +#!/bin/sh +## Reset to normal: \033[0m +NORM="\033[0m" + +## Colors: +BLACK="\033[0;30m" +GRAY="\033[1;30m" +RED="\033[0;31m" +LRED="\033[1;31m" +GREEN="\033[0;32m" +LGREEN="\033[1;32m" +YELLOW="\033[0;33m" +LYELLOW="\033[1;33m" +BLUE="\033[0;34m" +LBLUE="\033[1;34m" +PURPLE="\033[0;35m" +PINK="\033[1;35m" +CYAN="\033[0;36m" +LCYAN="\033[1;36m" +LGRAY="\033[0;37m" +WHITE="\033[1;37m" + +## Backgrounds +BLACKB="\033[0;40m" +REDB="\033[0;41m" +GREENB="\033[0;42m" +YELLOWB="\033[0;43m" +BLUEB="\033[0;44m" +PURPLEB="\033[0;45m" +CYANB="\033[0;46m" +GREYB="\033[0;47m" + +## Attributes: +UNDERLINE="\033[4m" +BOLD="\033[1m" +INVERT="\033[7m" + +## Cursor movements +CUR_UP="\033[1A" +CUR_DN="\033[1B" +CUR_LEFT="\033[1D" +CUR_RIGHT="\033[1C" + +## Start of display (top left) +SOD="\033[1;1f" diff --git a/.config/shells/utils/cpwdrc b/.config/shells/utils/cpwdrc new file mode 100755 index 0000000..d3b9ec4 --- /dev/null +++ b/.config/shells/utils/cpwdrc @@ -0,0 +1,10 @@ +#!/bin/sh +## Collapsed Directory +_collapsed_pwd() { + pwd | perl -pe ' + BEGIN { + binmode STDIN, ":encoding(UTF-8)"; + binmode STDOUT, ":encoding(UTF-8)"; + }; s|^$ENV{HOME}|~|g; s|/([^/.])[^/]*(?=/)|/$1|g; s|/\.([^/])[^/]*(?=/)|/.$1|g +' +} diff --git a/.config/shells/utils/dirrc b/.config/shells/utils/dirrc new file mode 100755 index 0000000..99fb98f --- /dev/null +++ b/.config/shells/utils/dirrc @@ -0,0 +1,9 @@ +#!/bin/sh + +alias b="cd ~/.local/bin" +alias d="cd ~/Documents" +alias dw="cd ~/Downloads" +alias p="cd ~/Documents/Projects" +alias m="cd ~/Documents/musings" +alias c="cd ~/.config" + diff --git a/.config/shells/utils/funcrc b/.config/shells/utils/funcrc new file mode 100755 index 0000000..9b31a79 --- /dev/null +++ b/.config/shells/utils/funcrc @@ -0,0 +1,22 @@ +#!/bin/sh + +cdl () { cd "${@}" && ls ;} +mkc () { mkdir "${@}" && cd "${@}" ;} + +color_wrap() { + printf "%s%s%s" %{$fg_bold[$1]%} $2 %{$reset_color%} +} + +git_good() { + REPO="$(git config --get remote.origin.url 2>/dev/null | sed -n -E 's|.*/(.*)\.git|\1|p' | tr -d '\n' )" + BRANCH="$(git branch 2>/dev/null | sed -n -E 's/\* (.*)/\1/p' | tr -d '\n')" + [[ -n $BRANCH ]] && color_wrap cyan "[$REPO::$BRANCH] " +} + +error_code() { + if [[ $1 != 0 ]]; + then + color_wrap red "["$1"]" + fi +} + diff --git a/.config/shells/zsh/.zshrc b/.config/shells/zsh/.zshrc index b9c5a1f..652d12f 100644 --- a/.config/shells/zsh/.zshrc +++ b/.config/shells/zsh/.zshrc @@ -2,33 +2,24 @@ if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && exec tmux fi -color_wrap() { - printf "%s%s%s" %{$fg_bold[$1]%} $2 %{$reset_color%} -} - -git_good() { - REPO="$(git config --get remote.origin.url 2>/dev/null | sed -n -E 's|.*/(.*)\.git|\1|p' | tr -d '\n' )" - BRANCH="$(git branch 2>/dev/null | sed -n -E 's/\* (.*)/\1/p' | tr -d '\n')" - [[ -n $BRANCH ]] && color_wrap cyan "[$REPO::$BRANCH] " -} - -error_code() { - if [[ $1 != 0 ]]; - then - color_wrap red "["$1"]" - fi -} - source ~/.zprofile export SHELLDIR="$XDG_CONFIG_HOME/shells" export ZSH="$SHELLDIR/zsh" autoload -U +X compinit -compinit -d $XDG_CACHE_HOME/zcompdump-artix-5.8 +compinit -d $XDG_CACHE_HOME/zcompdump fpath=($ZSH/plugins/zsh-completions/src $fpath) -source $SHELLDIR/aliasrc -source $SHELLDIR/dirrc -source $SHELLDIR/colorsrc # contians color substituions -source $SHELLDIR/cpwdrc # contains _collapsed_pwd + +for CONFIG_FILE in $SHELLDIR/utils/*; +do + [[ -f $CONFIG_FILE ]] && source $CONFIG_FILE +done + +export OS="$(uname -s)" +for CONFIG_FILE in $SHELLDIR/utils/$OS/*; +do + [[ -f $CONFIG_FILE ]] && source $CONFIG_FILE +done + bindkey -v bindkey -s ^f "tmux-sessionizer\n" HISTFILE="$XDG_CACHE_HOME/zshHIST" @@ -36,9 +27,8 @@ SAVEHIST=100 HISTSIZE=5000 setopt prompt_subst autoload -U colors && colors -PROMPT='%{$fg_bold[$shColor]%}$comSym%{$reset_color%} in %{$fg_bold[$shColor]%}%c%{$reset_color%} $(ret=$?; git_good ; error_code $ret) +PROMPT='%{$fg_bold[$shColor]%}$comSym%{$reset_color%} in %{$fg_bold[$shColor]%}%~%{$reset_color%} $(ret=$?; git_good ; error_code $ret) → ' source $ZSH/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh source $ZSH/plugins/fzf-tab/fzf-tab.zsh -source $SHELLDIR/funcrc -- cgit v1.2.3