From ad4bd0850b4421044ce96975fbdd234153422130 Mon Sep 17 00:00:00 2001 From: timmermansjoy <61321383+timmermansjoy@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:42:54 +0000 Subject: [PATCH] cleaned up unused code --- basic/functions/_c | 4 --- basic/functions/c | 12 ------- basic/functions/extract | 43 +++++++++++----------- basic/shell/custom.sh | 18 +++++----- basic/shell/index.zsh | 80 +++++++++++++++++++++-------------------- 5 files changed, 70 insertions(+), 87 deletions(-) delete mode 100644 basic/functions/_c delete mode 100644 basic/functions/c diff --git a/basic/functions/_c b/basic/functions/_c deleted file mode 100644 index d77f314..0000000 --- a/basic/functions/_c +++ /dev/null @@ -1,4 +0,0 @@ -#compdef c -_files -W $PROJECTS -/ - -# See further documentation in `functions/c`. diff --git a/basic/functions/c b/basic/functions/c deleted file mode 100644 index 0318e67..0000000 --- a/basic/functions/c +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# This lets you quickly jump into a project directory. -# -# Type: -# -# c -# -# ...to autocomplete on all of your projects in the directories specified in -# `functions/_c`. - -cd "$PROJECTS/$1" diff --git a/basic/functions/extract b/basic/functions/extract index 018d569..a74c5c0 100644 --- a/basic/functions/extract +++ b/basic/functions/extract @@ -2,26 +2,25 @@ # Usage: extract # Description: extracts archived files / mounts disk images # Note: .dmg/hdiutil is Mac OS X-specific. -extract () { - if [ -f $1 ]; then - case $1 in - *.tar.bz2) tar -jxvf $1 ;; - *.tar.gz) tar -zxvf $1 ;; - *.bz2) bunzip2 $1 ;; - *.dmg) hdiutil mount $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar -xvf $1 ;; - *.tbz2) tar -jxvf $1 ;; - *.tgz) tar -zxvf $1 ;; - *.zip) unzip $1 ;; - *.ZIP) unzip $1 ;; - *.pax) cat $1 | pax -r ;; - *.pax.Z) uncompress $1 --stdout | pax -r ;; - *.Z) uncompress $1 ;; - *) echo "'$1' cannot be extracted/mounted via extract()" ;; - esac - else - echo "'$1' is not a valid file" - fi +extract() { + if [ -f $1 ]; then + case $1 in + *.tar.bz2) tar -jxvf $1 ;; + *.tar.gz) tar -zxvf $1 ;; + *.bz2) bunzip2 $1 ;; + *.dmg) hdiutil mount $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar -xvf $1 ;; + *.tbz2) tar -jxvf $1 ;; + *.tgz) tar -zxvf $1 ;; + *.zip) unzip $1 ;; + *.ZIP) unzip $1 ;; + *.pax) cat $1 | pax -r ;; + *.pax.Z) uncompress $1 --stdout | pax -r ;; + *.Z) uncompress $1 ;; + *) echo "'$1' cannot be extracted/mounted via extract()" ;; + esac + else + echo "'$1' is not a valid file" + fi } - diff --git a/basic/shell/custom.sh b/basic/shell/custom.sh index 561230e..82a47cb 100644 --- a/basic/shell/custom.sh +++ b/basic/shell/custom.sh @@ -3,32 +3,32 @@ # Custom functions function top_commands { - cat ~/.zsh_history | format_history | head -n20 + cat ~/.zsh_history | format_history | head -n20 } alias tc=top_commands function top_recent_commands { - tail -n1000 ~/.zsh_history | format_history | head -n20 + tail -n1000 ~/.zsh_history | format_history | head -n20 } alias trc=top_recent_commands function format_history { - cut -d ';' -f 2- 2>/dev/null | - awk '{a[$1]++ } END{for(i in a){print a[i] " " i}}' | - sort -rn + cut -d ';' -f 2- 2>/dev/null | + awk '{a[$1]++ } END{for(i in a){print a[i] " " i}}' | + sort -rn } # Get weather report function weather { - curl -s "http://wttr.in/${1:-Hasselt}" | head -n 27 + curl -s "http://wttr.in/${1:-Hasselt}" | head -n 27 } alias weer="weather" # Get wifi password of given SSID function wifi_password { - wifi_name=$1 - security find-generic-password -ga "$wifi_name" | grep "password:" + wifi_name=$1 + security find-generic-password -ga "$wifi_name" | grep "password:" } #remap defaults @@ -40,10 +40,8 @@ alias lhost="open http://localhost:8080" alias localh="open http://localhost:8080" alias dotfile='e ~/.dotfiles' alias dotfiles='e ~/.dotfiles' -alias cpu="htop" alias myip="curl http://ipecho.net/plain; echo" alias finder="open ." -alias pxl="cd /Users/Joy/Stack/PXL/3e_jaar" # Programs shortcuts alias s="osascript -e 'tell application \"Safari\" to activate'" diff --git a/basic/shell/index.zsh b/basic/shell/index.zsh index 7bcd14a..f860b37 100644 --- a/basic/shell/index.zsh +++ b/basic/shell/index.zsh @@ -1,37 +1,44 @@ ###################################### -# config +# Ensure Shell Compatibility +###################################### +if [[ -z "$ZSH_VERSION" ]]; then + echo "Error: This configuration is intended for zsh." + return 1 +fi + +###################################### +# Validate DOTFILES Variable +###################################### +if [[ -z "$DOTFILES" ]]; then + echo "Error: DOTFILES variable is not set." + return 1 +fi + +###################################### +# Config ###################################### export LSCOLORS="exfxcxdxbxegedabagacad" export CLICOLOR=true +# Load functions fpath=($DOTFILES/basic/functions $fpath) +for file in $DOTFILES/basic/functions/*; do + [ -r "$file" ] && source "$file" +done -autoload -U $DOTFILES/basic/functions/*(:t) +# Initialize completion system +autoload -Uz compinit +compaudit | xargs chmod g-w,o-w 2>/dev/null +compinit -u HISTFILE=~/.zsh_history HISTSIZE=10000 SAVEHIST=10000 -setopt NO_BG_NICE # don't nice background tasks -setopt NO_HUP -setopt NO_LIST_BEEP -setopt LOCAL_OPTIONS # allow functions to have local options -setopt LOCAL_TRAPS # allow functions to have local traps -setopt HIST_VERIFY -setopt SHARE_HISTORY # share history between sessions ??? -setopt EXTENDED_HISTORY # add timestamps to history -setopt PROMPT_SUBST -setopt CORRECT -setopt COMPLETE_IN_WORD -setopt IGNORE_EOF - -setopt APPEND_HISTORY # adds history -setopt INC_APPEND_HISTORY SHARE_HISTORY # adds history incrementally and share it across sessions -setopt HIST_IGNORE_ALL_DUPS # don't record dupes in history -setopt HIST_REDUCE_BLANKS - -# don't expand aliases _before_ completion has finished -# like: git comm-[tab] +setopt NO_BG_NICE NO_HUP NO_LIST_BEEP LOCAL_OPTIONS LOCAL_TRAPS +setopt HIST_VERIFY SHARE_HISTORY EXTENDED_HISTORY PROMPT_SUBST +setopt CORRECT COMPLETE_IN_WORD IGNORE_EOF APPEND_HISTORY +setopt INC_APPEND_HISTORY SHARE_HISTORY HIST_IGNORE_ALL_DUPS HIST_REDUCE_BLANKS setopt complete_aliases bindkey '^[^[[D' backward-word @@ -42,39 +49,34 @@ bindkey '^[[3~' delete-char bindkey '^?' backward-delete-char ###################################### -# window +# Window ###################################### -# From http://dotfiles.org/~_why/.zshrc -# Sets the window title nicely no matter where you are function title() { - # escape '%' chars in $1, make nonprintables visible - a=${(V)1//\%/\%\%} - - # Truncate command, and join lines. - a=$(print -Pn "%40>...>$a" | tr -d "\n") + local input="${1:-Untitled}" + local escaped_input="${input//\%/\%\%}" + local truncated=$(print -Pn "%40>...>$escaped_input" | tr -d "\n") case $TERM in screen) - print -Pn "\ek$a:$3\e\\" # screen title (in ^A") + print -Pn "\ek$truncated:$3\e\\" ;; - xterm*|rxvt) - print -Pn "\e]2;$2\a" # plain xterm title ($3 for pwd) + xterm* | rxvt) + print -Pn "\e]2;$truncated\a" ;; + *) ;; esac } ###################################### -# completion +# Completion ###################################### -# matches case insensitive for lowercase zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' - -# pasting with tabs doesn't perform completion zstyle ':completion:*' insert-tab pending +zstyle ':completion:*' completer _complete _ignored _approximate +zstyle ':completion:*' verbose yes ###################################### -# customizations +# Customizations ###################################### source $DOTFILES/basic/shell/custom.sh - chpwd() ls -F