Skip to content

Instantly share code, notes, and snippets.

@innateessence
Last active October 20, 2023 16:48
Show Gist options
  • Save innateessence/1ed24c9a67eded10c053fda2544a31e0 to your computer and use it in GitHub Desktop.
Save innateessence/1ed24c9a67eded10c053fda2544a31e0 to your computer and use it in GitHub Desktop.
Zshrc - Style/Aliases/Exports/Functions
#!/bin/zsh
#===============================#
# #
# ALIASES #
# #
#===============================#
alias ffs='eval "sudo $(fc -ln -1)"'
# CD
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
alias ~="cd ~"
# ls
alias ls="/bin/ls --color=auto"
alias lh="ls -hl"
alias la="ls -la"
# mkdir
alias mk="mkdir -p"
alias mkdir="mkdir -p"
# cp
alias cp="cp -i"
# mv
alias mv="mv -i"
# Use less fuck
alias sl=ls
# CAREFUL
alias rm="trash"
alias Rm="sudo trash"
alias RM="sudo trash"
# Sudo Damnit! (caps = sudo)
alias Pacman="sudo pacman"
alias paste='~/scripts/pb'
alias backup-system='sudo /home/jack/scripts/backup-system'
alias ffmpeg-recursive='/home/jack/scripts/helpers/plex/ffmpeg-recursive.py'
alias music-reload='~/scripts/audio/music-reload.sh'
alias installfont='sudo fc-cache -f -v'
alias pdf='masterpdfeditor5'
alias TERM.kitty='export TERM=xterm-kitty'
alias TERM.xterm='export TERM=xterm-256color'
alias reload='source ~/.zshrc'
alias git=hub
alias py="python"
alias py2="python2"
alias bpy="bpython"
alias ppy="ptpython"
alias ptpy="ptpython"
alias SS=ag
alias music=ncmpcpp
alias email=neomutt
alias newsbeuter=newsboat
alias mutt=neomutt
alias ls-fonts=xlsfonts
alias nvidiatop=nvtop
alias P='yaourt'
alias copy=cp
alias notes="ranger ~/Documents/notes"
alias printenv='printenv | grep --invert-match "LS_COLORS"'
#!/bin/zsh
#===============================#
# #
# Exports #
# #
#===============================#
# PATH - tr to split/merge, awk to remove duplicates, sort just cuz
PATH=$(echo "$PATH:$HOME/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/jack/.gem/ruby/2.4.0/bin" | tr ':' '\n' | awk '!a[$0]++' | sort | tr '\n' ':')
# C Programming
export CC='clang'
# Compilation flags
export ARCHFLAGS="-arch x86_64"
# Locale/Langs
export LANG='en_US.utf8'
export LC_ALL='en_US.utf8'
# Programs
export EDITOR="nvim"
export VISUAL="nvim"
export BROWSER="qutebrowser"
export FILE_BROWSER="ranger"
export VID_PLAYER="vlc"
export AUDIO_PLAYER="mpd"
# Monitors
export MONITOR_MAIN="HDMI-0"
export MONITOR_LEFT="DVI-I-1"
export MONITOR_RIGHT="DVI-D-0"
# Fzf
export FZF_COMPLETION_TRIGGER="~~" # Trigger
export FZF_COMPLETION_OPTS="-x +c" # args/command line options
export FZF_DEFAULT_COMMAND='ag -g ""' # use ag instead of find
source /usr/share/fzf/key-bindings.zsh
#========================#
# #
# Evals #
# #
#========================#
# Custom COLORZ
eval $( dircolors -b /home/jack/.dotfiles/LS_COLORS )
export LS_COLORS
#===============================#
# #
# Tab Completion #
# #
#===============================#
# Syntax Highlighting
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
function clamscan-full () {
clamscan -a -o -r -z --detect-structured --structured-ssn-format=2 --detect-broken --enable-stats --stdout --exclude=metasploit.* -l /var/log/custom/clamscan.log
}
function hist-rofi(){
fc -lnr 1 | uniq --unique | rofi -dmenu -p 'Select a command: ' | xclip
}
function err(){ echo >&2 `tput bold; tput setaf 1`"[-] ERROR: ${*}"`tput sgr0`;exit 1 }
function warn(){ echo >&2 `tput bold; tput setaf 1`"[!] WARNING: ${*}"`tput sgr0` }
function msg(){ echo `tput bold; tput setaf 2`"[+] ${*}"`tput sgr0` }
function git-home(){ git rev-parse --show-toplevel }
function git-ignore(){ repo_home=$(git rev-parse --show-toplevel); for filename in ${@}; do echo $filename >> $repo_home/.gitignore; done }
function decrypt() { gpg2 --output ${1:0:-4} --decrypt $1 }
function find_symlinks(){ ls -lR "${@}" | grep ^ }
function git-ignore(){ repo_home=$(git rev-parse --show-toplevel); for filename in ${@}; do echo $filename >> $repo_home/.gitignore; done }
function decrypt() { gpg2 --output ${1:0:-4} --decrypt $1 }
function find_symlinks(){ ls -lR "${@}" | grep ^ }
function mkquickcd(){
alias cd.="cd ~/.dotfiles"
for f in ~/.dotfiles/*
do if [[ -d "$f" ]]
then x=($(echo "$f" | tr "/" " "))
x=$x[-1]
alias "cd.$x"="cd $f"
fi; done ; unset x ; unset f
}
function codi() {
local syntax="${1:-python}"
shift
vim -c \
"let g:startify_disable_at_vimenter = 1 |\
set bt=nofile ls=0 noru nonu nornu |\
hi ColorColumn ctermbg=NONE |\
hi VertSplit ctermbg=NONE |\
hi NonText ctermfg=0 |\
Codi $syntax" "$@"
}
function untar(){ while [ ${#} != 0 ]; do if [ -f "${1}" ]; then case "${1}" in
*.tar.xz); tar xfv "${1}";shift;;
*.tar.bz2); tar xjvf "${1}";shift;;
*.tar.gz); tar xzvf "${1}";shift;;
*.bz2); bunzip2 "${1}";shift;;
*.rar); rar x "${1}";shift;;
*.gz); gunzip "${1}";shift;;
*.tar); tar xf "${1}";shift;;
*.tbz2); tar xjvf "${1}";shift;;
*.tgz); tar xzvf "${1}";shift;;
*.zip); unzip "${1}";shift;;
*.Z); uncompress "${1}";shift;;
*.7z); 7z x "${1}";shift;;
*) echo "$1 cannot be extracted via extract-file"; shift
esac; else; echo "$1 is not a valid file"; shift; fi; done}
function git-rm-from-repo(){
cwd=$pwd
repo_home=$(git rev-parse --show-toplevel)
#cd $repo_home
for filename in ${@}; do
cp $filename $filename.bak
git filter-branch --force --index-filter "git update-index --remove $filename"
# --prune-empty --tag-name-filter cat -- --all
echo $filename >> $repo_home/.gitignore
mv $filename.bak $filename
git add $repo_home/.gitignore
git commit -m '[!] repo rewrite'
git push --force
done
cat $repo_home/.gitignore | uniq > $repo_home/._gitignore
rm $repo_home/.gitignore
mv $repo_home/._gitignore $repo_home/.gitignore
unset repo_home ; unset cwd
}
function cpv()
#https://raw.githubusercontent.com/nachoparker/cpv/master/cpv.sh
{
local DST=${@: -1} # last element
local SRC=( ${@: 1 : $# - 1} ) # array with rest of elements
# checks
type pv &>/dev/null || { echo "install pv first"; return 1; }
[ $# -lt 2 ] && { echo "too few args" ; return 1; }
# special invocation
function cpv_rename()
{
local SRC="$1"
local DST="$2"
local DSTDIR="$( dirname "$DST" )"
# checks
if [ $# -ne 2 ]; then echo "too few args" ; return 1; fi
if ! [ -e "$SRC" ]; then echo "$SRC doesn't exist" ; return 1; fi
if [ -d "$SRC" ]; then echo "$SRC is a dir" ; return 1; fi
if ! [ -d "$DSTDIR" ]; then echo "$DSTDIR does not exist"; return 1; fi
# actual copy
echo -e "\n$SRC 🡺 $DST"
pv "$SRC" >"$DST"
}
# special case for cpv_rename()
if ! [ -d "$DST" ]; then cpv_rename "$@"; return $?; fi;
# more checks
for src in "${SRC[@]}"; do
local dst="$DST/$( basename "$src" )"
if ! [ -e "$src" ]; then echo "$src doesn't exist" ; return 1;
elif [ -e "$dst" ]; then echo "$dst already exists"; return 1; fi
done
# actual copy
for src in "${SRC[@]}"; do
if ! [ -d "$src" ]; then
local dst="$DST/$( basename "$src" )"
echo -e "\n$src 🡺 $dst"
pv "$src" > "$dst"
else
local dir="$DST/$( basename "$src" )"
mkdir "$dir" || continue
local srcs=( $src/* )
cpv "${srcs[@]}" "$dir";
fi
done
unset cpv_rename
}
function checksums () {
checkers=(md5sum sha1sum sha256sum)
for checker in $checkers
do
which $checker &>/dev/null
if [[ $? -eq 0 ]]; then
for file in "${@}"
do
echo "$checker $($checker $file)"
done
fi
done
}
#!/bin/zsh
#=========================#
# #
# Style #
# #
#=========================#
# Aliases and functions
ZSH_HIGHLIGHT_STYLES[alias]='fg=green,bold'
ZSH_HIGHLIGHT_STYLES[function]='fg=green,bold'
# Commands and builtins
ZSH_HIGHLIGHT_STYLES[command]="fg=green,bold"
ZSH_HIGHLIGHT_STYLES[hashed-command]="fg=green,bold"
ZSH_HIGHLIGHT_STYLES[builtin]="fg=green,bold"
# Paths
ZSH_HIGHLIGHT_STYLES[path]='fg=white,underline'
# Globbing
ZSH_HIGHLIGHT_STYLES[globbing]='fg=yellow,bold'
# Options and arguments
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=red'
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=red'
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]="fg=yellow"
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]="fg=yellow"
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]="fg=yellow"
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]="fg=yellow"
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=yelloiw"
# PATTERNS
ZSH_HIGHLIGHT_PATTERNS+=('rm -f*' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('rm * -f*' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('sudo *' 'fg=white,bold,bg=red')
#===============================#
# #
# ZStyle #
# #
#===============================#
# ignore completion to commands we don't have
zstyle ':completion:*:functions' ignored-patterns '_*'
# format autocompletion style
zstyle ':completion:*:descriptions' format "%{$c1%}%d%{$reset_color%}"
zstyle ':completion:*:corrections' format "%{$c3%}%d%{$reset_color%}"
zstyle ':completion:*:messages' format "%{$c1%}%d%{$reset_color%}"
zstyle ':completion:*:warnings' format "%BSorry, no matches for: %d%b"
#zstyle ':completion:*:warnings' format "%{$c1%}%d%{$reset_color%}"
# zstyle show completion menu if 2 or more items to select
zstyle ':completion:*' menu select=2
# zstyle kill menu
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=36=31"
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' separate-sections 'yes'
zstyle ':completion:*' list-dirs-first true
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' menu select=200
zstyle ':completion:*' use-perl=1
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*:cd:*' ignore-parents parent pwd
zstyle ':completion:*:(all-|)files' ignored-patterns '*.un~'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh-cache
zstyle ':completion:*:processes' command 'ps -axw'
zstyle ':completion:*:processes-names' command 'ps -awxho command'
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:*:(mplayer|vlc):*' tag-order files
zstyle ':completion:*:*:(mplayer|vlc):*' file-patterns \
'*.(rmvb|mkv|mpg|wmv|mpeg|avi|flv|mp3|mp4|flac|ogg):video' \
'*:all-files' '*(-/):directories'
zstyle ':completion:*:*:(vim|nvim|rview|vimdiff|xxd):*:*files' \
ignored-patterns '*~|*.(old|bak|zwc|viminfo|rxvt-*|zcompdump)|pm_to_blib|cover_db|blib|pyc|exe' \
file-sort modification
zstyle ':completion:*:*:(vim|nvim|rview|vimdiff|xxd):*' \
file-sort modification
zstyle ':completion:*:*:(vim|nvim|rview|vimdiff|xxd):*' \
tag-order files
#zstyle ':completion:*:vim:*:directories' ignored-patterns \*
zstyle ':completion:*:*:(scp):*' \
file-sort modification
zstyle ':completion:*:*:(cd):*:*files' ignored-patterns '*~' file-sort access
zstyle ':completion:*:*:(cd):*' file-sort access
zstyle ':completion:*:*:(cd):*' menu select
zstyle ':completion:*:*:(cd):*' completer _history
zstyle ':completion:*:*:perl:*' file-patterns '*'
zstyle ':completion:*:descriptions' \
format $'%{- \e[38;5;137;1m\e[48;5;234m%}%B%d%b%{\e[m%}'
zstyle ':completion:*:warnings' \
format $'%{No match for \e[38;5;240;1m%}%d%{\e[m%}'
zstyle ':completion:*:*:apvlv:*' tag-order files
zstyle ':completion:*:*:apvlv:*' file-patterns '*.pdf'
zstyle ':completion:most-accessed-file:*' match-original both
zstyle ':completion:most-accessed-file:*' file-sort access
zstyle ':completion:most-accessed-file:*' file-patterns '*:all\ files'
zstyle ':completion:most-accessed-file:*' hidden all
zstyle ':completion:most-accessed-file:*' completer _files
zstyle ':completion:*:(scp|sftp|ftp|lftp):*' group-order \
users files all-files hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' tag-order \
users 'hosts:-host hosts:-domain:domain hosts:-ipaddr:IP\ address *'
zstyle ':completion:*:ssh:*' group-order \
hosts-domain hosts-host users hosts-ipaddr
zstyle ':completion:*:(ssh|scp|ftp|sftp|lftp):*:hosts-host' ignored-patterns \
'*.*' loopback localhost
zstyle ':completion:*:(ssh|scp|ftp|sftp|lftp):*:hosts-domain' ignored-patterns \
'<->.<->.<->.<->' '^*.*' '*@*'
zstyle ':completion:*:(ssh|scp|ftp|sftp|lftp):*:hosts-ipaddr' ignored-patterns \
'^<->.<->.<->.<->' '127.0.0.<->'
zstyle ':completion:*:(ssh|scp|ftp|sftp|lftp):*:users' ignored-patterns \
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
mailman mailnull mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
autoload -Uz compinit
compinit
#===============================#
# #
# Settings #
# #
#===============================#
# Override fzf function, use $(ag) instead of $(find)
function _fzf_compgen_path() {
ag -g "" "$1"
}
for f in /home/jack/.dotfiles/zsh/*.zsh
do source "$f"
done
unset f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment