From 2dc486fb891e65658dff83ab34ca8878756a6a90 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Fri, 18 Oct 2024 21:52:28 -0500 Subject: initial commit --- zscripts/!rootcolors.zsh | 3 + zscripts/.lfub.zsh | 27 +++++++ zscripts/aliasrc.zsh | 64 +++++++++++++++++ zscripts/hosts/aliasrc.G3N2.zsh | 6 ++ zscripts/hosts/aliasrc.T495.zsh | 1 + zscripts/hosts/aliasrc.desktop.zsh | 12 ++++ zscripts/hosts/aliasrc.libreX60.zsh | 11 +++ zscripts/hosts/aliasrc.voidx250.zsh | 8 +++ zscripts/hosts/colors.desktop.zsh | 9 +++ zscripts/hosts/colors.voidx250.zsh | 9 +++ zscripts/keybindrc.zsh | 24 +++++++ zscripts/nicegit.zsh | 31 ++++++++ zscripts/shortcuts.zsh | 12 ++++ zscripts/terminalname.zsh | 8 +++ zscripts/termuxprompt.zsh | 8 +++ zscripts/vicursor.zsh | 21 ++++++ zscripts/zplug.zsh | 136 ++++++++++++++++++++++++++++++++++++ zscripts/zshcompmenu.zsh | 18 +++++ 18 files changed, 408 insertions(+) create mode 100755 zscripts/!rootcolors.zsh create mode 100755 zscripts/.lfub.zsh create mode 100755 zscripts/aliasrc.zsh create mode 100755 zscripts/hosts/aliasrc.G3N2.zsh create mode 120000 zscripts/hosts/aliasrc.T495.zsh create mode 100755 zscripts/hosts/aliasrc.desktop.zsh create mode 100755 zscripts/hosts/aliasrc.libreX60.zsh create mode 100755 zscripts/hosts/aliasrc.voidx250.zsh create mode 100755 zscripts/hosts/colors.desktop.zsh create mode 100755 zscripts/hosts/colors.voidx250.zsh create mode 100755 zscripts/keybindrc.zsh create mode 100755 zscripts/nicegit.zsh create mode 100755 zscripts/shortcuts.zsh create mode 100755 zscripts/terminalname.zsh create mode 100755 zscripts/termuxprompt.zsh create mode 100755 zscripts/vicursor.zsh create mode 100755 zscripts/zplug.zsh create mode 100755 zscripts/zshcompmenu.zsh (limited to 'zscripts') diff --git a/zscripts/!rootcolors.zsh b/zscripts/!rootcolors.zsh new file mode 100755 index 0000000..d146aa5 --- /dev/null +++ b/zscripts/!rootcolors.zsh @@ -0,0 +1,3 @@ +#!/usr/bin/env zsh + +[ $EUID = 0 ] && declare col{br,name,at,host,dir}=red && clear # Clear to get rid of last login message diff --git a/zscripts/.lfub.zsh b/zscripts/.lfub.zsh new file mode 100755 index 0000000..2e1f7f4 --- /dev/null +++ b/zscripts/.lfub.zsh @@ -0,0 +1,27 @@ +#!/bin/sh +# This is a wrapper script for lf that allows it to create image previews with +# ueberzug. This works in concert with the lf configuration file and the +# lf-cleaner script. + +cleanuplf() { + exec 3>&- + \rm "$FIFO_UEBERZUG" +} + +lfub() { + dircache=/tmp/$USER-lflastdir + lfopt="--last-dir-path=$dircache" + if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then + lf "$lfopt" "$@" + else + export FIFO_UEBERZUG="/tmp/ueberzug-$$" + mkfifo "$FIFO_UEBERZUG" + ueberzug layer -s <"$FIFO_UEBERZUG" -p json & + exec 3>"$FIFO_UEBERZUG" + trap cleanuplf HUP INT QUIT TERM PWR EXIT + lf "$lfopt" "$@" 3>&- + fi + [ -f "$dircache" ] && dir="$(cat "$dircache")" && [ -d "$dir" ] && cd "$dir" +} + +alias lf="lfub" diff --git a/zscripts/aliasrc.zsh b/zscripts/aliasrc.zsh new file mode 100755 index 0000000..f4e5035 --- /dev/null +++ b/zscripts/aliasrc.zsh @@ -0,0 +1,64 @@ +#!/usr/bin/env zsh + +# Replacement programs +typeset -A repaliases=( + #alias replacement + htop htim + mutt neomutt + vim nvim + sudo "${SUDO:- }" + neofetch fastfetch +) +for alias rep in ${(kv)repaliases}; do + command -v $rep >/dev/null && alias $alias=$rep +done # Tests if replacement exists before creating alias + + +# Shorten program names +alias \ + open="xdg-open" \ + smci="sudo make clean install" \ + smi="sudo make install" \ + su="sudo su -l" \ + +# Power scripts +alias \ + halt="launch shutdown" \ + off="launch shutdown" \ + reboot="launch reboot" \ + zzz="launch suspend" \ + +# Colorize command output +alias \ + bat="bat --theme='Monokai Extended'" \ + diff="diff --color=auto" \ + exa="exa --icons -a --group-directories-first" \ + grep="grep --color=auto -I --ignore-case --line-number" \ + ip="ip --color=auto" \ + ls="ls -vAhN --color=auto --group-directories-first" \ + +# (Non)-Verbosity +alias \ + cp="cp -iv" \ + dd="sudo dd status=progress bs=4M" + ffmpeg="ffmpeg -hide_banner" \ + ffprobe="ffprobe -hide_banner" \ + mkd="mkdir -p" \ + mv="mv -iv" \ + rm="rm -v" \ + +# Miscellaneous +alias \ + yt-dlp-album="yt-dlp -x -o '%(uploader)s (%(upload_date>%Y)s) - %(playlist_title)s%%%(playlist_index)s - %(title)s.%(ext)s'" \ + yt-dlp="yt-dlp -o '%(uploader)s - %(title)s.%(ext)s'" \ + +# Clean home directory +alias \ + mbsync="mbsync --config $MBSYNCRC" \ + startx="startx $X11CONFIG/xinitrc" \ + +# Copy-pasting from internet +alias \ + \$="" \ + \#="${SUDO-sudo}" \ + diff --git a/zscripts/hosts/aliasrc.G3N2.zsh b/zscripts/hosts/aliasrc.G3N2.zsh new file mode 100755 index 0000000..8e8d2a5 --- /dev/null +++ b/zscripts/hosts/aliasrc.G3N2.zsh @@ -0,0 +1,6 @@ +#!/bin/sh + +# Package Management +alias \ + e="sudo emerge" \ + diff --git a/zscripts/hosts/aliasrc.T495.zsh b/zscripts/hosts/aliasrc.T495.zsh new file mode 120000 index 0000000..6c84487 --- /dev/null +++ b/zscripts/hosts/aliasrc.T495.zsh @@ -0,0 +1 @@ +aliasrc.desktop.zsh \ No newline at end of file diff --git a/zscripts/hosts/aliasrc.desktop.zsh b/zscripts/hosts/aliasrc.desktop.zsh new file mode 100755 index 0000000..141212f --- /dev/null +++ b/zscripts/hosts/aliasrc.desktop.zsh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Package Management +alias \ + d="sudo dnf" \ + dnf="sudo dnf" \ + +# Shorten program names +alias \ + systemctl="sudo systemctl" \ + sd="systemctl" \ + diff --git a/zscripts/hosts/aliasrc.libreX60.zsh b/zscripts/hosts/aliasrc.libreX60.zsh new file mode 100755 index 0000000..1180171 --- /dev/null +++ b/zscripts/hosts/aliasrc.libreX60.zsh @@ -0,0 +1,11 @@ +#!/bin/sh + +# Package Management +alias \ + apt="sudo apt" \ + +# Shorten program names +alias \ + systemctl="sudo systemctl" \ + sd="systemctl" \ + diff --git a/zscripts/hosts/aliasrc.voidx250.zsh b/zscripts/hosts/aliasrc.voidx250.zsh new file mode 100755 index 0000000..4bb85ea --- /dev/null +++ b/zscripts/hosts/aliasrc.voidx250.zsh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Package Management +alias \ + xi="sudo xbps-install" \ + xq="xbps-query -R --search" \ + xr="sudo xbps-remove" \ + diff --git a/zscripts/hosts/colors.desktop.zsh b/zscripts/hosts/colors.desktop.zsh new file mode 100755 index 0000000..dee7ed3 --- /dev/null +++ b/zscripts/hosts/colors.desktop.zsh @@ -0,0 +1,9 @@ +#!/usr/bin/env zsh + +if [ -n "$DISPLAY" ]; then + declare col{br,at}=57 + declare col{name,host}=13 + coldir=129 +else + declare col{br,name,at,host,dir}=magenta +fi diff --git a/zscripts/hosts/colors.voidx250.zsh b/zscripts/hosts/colors.voidx250.zsh new file mode 100755 index 0000000..910f1f9 --- /dev/null +++ b/zscripts/hosts/colors.voidx250.zsh @@ -0,0 +1,9 @@ +#!/usr/bin/env zsh + +if [ -n "$DISPLAY" ]; then + declare col{br,at}=green + declare col{name,host}=76 + coldir=40 +else + declare col{br,name,at,host,dir}=green +fi diff --git a/zscripts/keybindrc.zsh b/zscripts/keybindrc.zsh new file mode 100755 index 0000000..2f2e664 --- /dev/null +++ b/zscripts/keybindrc.zsh @@ -0,0 +1,24 @@ +#!/usr/bin/env zsh + +# Vi mode + requirements for ALL keybindings to work correctly +bindkey -v # Select viins keymap +KEYTIMEOUT=1 + +# Keybindings +autoload edit-command-line; zle -N edit-command-line # Edit line in Vim buffer +bindkey '^E' edit-command-line # Ctrl-e - edit line in Vim buffer + +bindkey '^[[P' delete-char # Delete Key +bindkey '^[[F' end-of-line # End Key +bindkey '^[[H' beginning-of-line # Home Key +bindkey '^[[2~' overwrite-mode # Insert Key +bindkey '^D' kill-whole-line # Ctrl-d - delete line +bindkey '^X' clear-screen # Ctrl-x - clear screen +bindkey '^H' backward-delete-word # Ctrl-Backspace - delete entire word behind cursor +bindkey '^[[3;5~' delete-word # Ctrl-Delete - delete currect word in front of the cursor +# History completion +bindkey '\e[A' history-search-backward # Up arrow - seach history backwards +bindkey '\e[B' history-search-forward # Down arrow - seach history forwards + +# Ignore ctrl-d to exit shell +setopt IGNORE_EOF diff --git a/zscripts/nicegit.zsh b/zscripts/nicegit.zsh new file mode 100755 index 0000000..276d98e --- /dev/null +++ b/zscripts/nicegit.zsh @@ -0,0 +1,31 @@ +#!/usr/bin/env zsh + +alias \ + ga="git add" \ + gpl="git pull" \ + gph="git push" \ + gl="git log" \ + gldaily='git log --pretty="format:- %s" --after="00:00" --before="24:00"' \ + + +function gc() { + if ! __is_diff; then + echo "Nothing to commit, working tree clean" + return + fi + + if [[ "$@" != "" ]]; then + commit="$@" + else + echo "Enter commit message:" && read commit + fi + git commit -m "$commit" +} + +function __is_diff() { + ! git diff --quiet HEAD $REF -- $DIR +} + +function gdf() { + __is_diff && git diff HEAD $RED -- $DIR || echo "Repo is unchanged" +} diff --git a/zscripts/shortcuts.zsh b/zscripts/shortcuts.zsh new file mode 100755 index 0000000..214b7f7 --- /dev/null +++ b/zscripts/shortcuts.zsh @@ -0,0 +1,12 @@ +#!/usr/bin/env zsh + +# TODO make this script more comprehensive to allow real aliases for directories +# Quick navigate to directories / open specific files +alias \ + cdc="cd ~/docs/src/programs" \ + cds="cd ~/docs/src/scripts" \ + cdw="cd ~/docs/src/sites" \ + vrc="vim ~/.config/nvim/init.vim" \ + xrc="cd ~/.config/x11" \ + zrc="cd ~/.config/zsh" \ + diff --git a/zscripts/terminalname.zsh b/zscripts/terminalname.zsh new file mode 100755 index 0000000..6e55d22 --- /dev/null +++ b/zscripts/terminalname.zsh @@ -0,0 +1,8 @@ +function xtitle () { + builtin print -n -- "\e]0;$@\a" +} + +# Updates the window title whenever a command is run +function precmd () { + xtitle "$(print -P ${USER}@${HOST} %~)" +} diff --git a/zscripts/termuxprompt.zsh b/zscripts/termuxprompt.zsh new file mode 100755 index 0000000..1442cc8 --- /dev/null +++ b/zscripts/termuxprompt.zsh @@ -0,0 +1,8 @@ +#!/usr/bin/env zsh + +if [ -n "$TERMUX_VERSION" ]; then + PS1="%B%F{green}[%F{blue}%U%~%u%F{green}]%f%b%(!.#.$) " + PS1OVERRIDE=1 + export ZPLUGINSDIR=~/.local/share/zsh/zplugins + export ZPLUGNOROOT=1 +fi diff --git a/zscripts/vicursor.zsh b/zscripts/vicursor.zsh new file mode 100755 index 0000000..3e4320d --- /dev/null +++ b/zscripts/vicursor.zsh @@ -0,0 +1,21 @@ +#!/usr/bin/env zsh + +# Change cursor shape for different vi modes +# Copied from LARBS +if [ -n "$DISPLAY" ]; then + function zle-keymap-select () { + case $KEYMAP in + vicmd) echo -n '\e[1 q';; # block + viins|main) echo -n '\e[5 q';; # beam + esac + } + zle -N zle-keymap-select + zle-line-init() { + #zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere) + echo -n "\e[5 q" + } + zle -N zle-line-init + echo -n '\e[5 q' # Use beam shape cursor on startup + preexec() { echo -n '\e[5 q' ;} # Use beam shape cursor for each new prompt +fi + diff --git a/zscripts/zplug.zsh b/zscripts/zplug.zsh new file mode 100755 index 0000000..27dc70f --- /dev/null +++ b/zscripts/zplug.zsh @@ -0,0 +1,136 @@ +#!/usr/bin/env zsh + +local home=~ +local zplugs="${ZDOTDIR:-$home/.}${ZDOTDIR:+/}zplugs" # Declare all variables using `local` to keep them away from the interactive shell +local zplugins="${ZPLUGINSDIR:-$home/.local/share/zsh/zplugins}" +#[[ $EUID != 0 ]] && [ -z "$ZPLUGNOROOT" ] && local sudo=${SUDO-sudo} + +function __zplugInstall() { + touch "$zplugs" + local pluglist=( `\grep -v '#' "$zplugs"` ) + local confirm plug + shift + for plug in "$@"; do; pluglist+=(${plug}); done + + $sudo mkdir -p "$zplugins" + + for plug in ${pluglist[@]}; do + [ -d "$zplugins/$(basename -s'.git' "$plug")" ] && continue + if ! `$sudo git -C "$zplugins" clone "$plug" "$(basename -s'.git' "$plug")"`; then + # Runs if git has an error + printf "Remove \"$plug\"? [y|n]: " + read confirm + case $confirm in + y|yes) pluglist=(${pluglist#$plug}) && echo "Repo Deleted" ;; + *) echo "Repo Kept" ;; + esac + fi + echo + done + for plug in ${pluglist[@]}; do echo "$plug"; done | sort -u > "$zplugs" + echo "All plugins installed and saved to $zplugs!\nDone" +} + +function __zplugUninstall() { + local pluglist=( `cat "$zplugs"` ) pluglistbn=() + local confirm i plug plugids plugig + + [ -z "$pluglist" ] && echo "No packages are installed!" && return + + $sudo mkdir -p "$zplugins" + echo "Listing all packages in $zplugins ..." + for i in {1..${#pluglist[@]}}; do + pluglistbn[$i]="$(basename -s'.git' "${pluglist[$i]}")" + printf '%3d) %s\n' $i "${pluglistbn[$i]}" + done + + echo + printf "Choose zsh plugin(s) to remove: " + read plugids + [ -z "$plugids" ] && echo "No plugins selected\nAborting" && return + + echo "\nListing selected plugins:" + for plugid in $=plugids; do + if [ -z ${pluglist[$plugid]} ]; then + echo "Error: input \"$plugid\" is not a valid plugin identifier" + return + fi + echo "\t${pluglistbn[$plugid]}" + done + + printf "\nReally remove all of these plugins? [y|n]: " + read confirm + case $confirm in + y|yes) ;; + n|no) echo "Aborted" && return ;; + *) echo "Input not understood\nAborted" && return ;; + esac + for plugid in $=plugids; do + printf '\t' + $sudo rm -vrf "$zplugins/${pluglistbn[$plugid]}" + pluglist[$plugid]="" + done + for plug in ${pluglist[@]}; do echo "$plug"; done | sort -u > "$zplugs" + echo "\nDone" +} + +function __zplugUpgrade() { + local plugdir + $sudo mkdir -p "$zplugins" + echo "Upgrading all packages...\n" + for plugdir in "$zplugins"/*; do; + basename "$plugdir" + $sudo git -C "$plugdir" pull; + echo + done + echo "Done" +} + +function __zplugList() { + mkdir -p "$zplugins" + echo "Listing all packages...\n" + ls "$zplugins" | nl -s') ' -w3 + echo "\nDone" +} + +function __zplugHelp() { + echo "Usage: zplug [install/add/i|uninstall/remove/r|upgrade/update/u|list/l|help/h] + install, add, i [packages] : Install plugins from config file & add any new plugins + uninstall, remove, r : Interactively remove plugins + upgrade, update, u : Update all installed plugins + list, l : List all installed plugins + help, h : Show this help menu + + All plugins are listed in $zplugs + All plugins are installed in $zplugins + + To install a plugin, just put it in the zplug file and run \"zplug install\" + or just run \"zplug install [plugin]\" where [plugin] is a link to download the + plugin using git + + For instance, \"https://github.com/zdharma-continuum/fast-syntax-highlighting\" is + a valid plugin link for the fast-syntax-highlighting plugin. + + To use your plugins, just put \"zplugInitialize\" as the last line of your zshrc!" +} + +function zplug() { + local cmd=${1:-h} + case $cmd in + install|add|i) __zplugInstall $@ ;; + uninstall|remove|r) __zplugUninstall ;; + upgrade|update|u) __zplugUpgrade ;; + list|l) __zplugList ;; + help|h) __zplugHelp ;; + *) echo "zplug: input \"$1\" not recognized!" && __zplugHelp ;; + esac +} + +function zplugInitialize() { + local plugin + if ! [ -d "$zplugins" ] && [ -f "$zplugs" ]; then + echo "zplug installing plugins..." + __zplugInstall 0 # Put in some value since there is a shift + fi + for plugin in "$zplugins"/*/*.zsh; do source "$plugin"; done 2>/dev/null +} diff --git a/zscripts/zshcompmenu.zsh b/zscripts/zshcompmenu.zsh new file mode 100755 index 0000000..0d471a5 --- /dev/null +++ b/zscripts/zshcompmenu.zsh @@ -0,0 +1,18 @@ +#!/usr/bin/env zsh + +# Basic auto/tab complete +autoload -U compinit +zstyle ':completion:*' menu select +zmodload zsh/complist +compinit -d "${XDG_CACHE_HOME:-$HOME/.config}/zcompdump" # Change where .zcompdump is stored +_comp_options+=(globdots) # Include hidden files. + +# Use ctrl-vi keys in tab complete menu +bindkey -M menuselect '^h' vi-backward-char +bindkey -M menuselect '^j' vi-down-line-or-history +bindkey -M menuselect '^k' vi-up-line-or-history +bindkey -M menuselect '^l' vi-forward-char +bindkey -v '^?' backward-delete-char + +# Options +setopt MENU_COMPLETE # Immediately insert first option from completion menu -- cgit v1.2.3