Created
December 5, 2023 09:33
-
-
Save rugbyprof/5d9dc33e970e28d7cf0c8b10acd9137d to your computer and use it in GitHub Desktop.
Additional zshrc quick commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ===================================================================================== | |
# MY STUFF | |
# ===================================================================================== | |
# User configuration | |
export EDITOR=nano | |
alias cp='cp -i' # Preferred 'cp' implementation | |
alias cpp='cp -iv' # Preferred 'cp' implementation | |
alias mv='mv -iv' # Preferred 'mv' implementation | |
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation | |
alias ll='ls -FGlAhp' # Preferred 'ls' implementation | |
alias la='ls -lah' | |
alias less='less -FSRXc' # Preferred 'less' implementation | |
cd() { builtin cd "$@"; ll; } # Always list directory contents upon 'cd' | |
alias cd..='cd ../' # Go back 1 directory level (for fast typers) | |
alias ..='cd ../' # Go back 1 directory level | |
alias ...='cd ../../' # Go back 2 directory levels | |
alias .3='cd ../../../' # Go back 3 directory levels | |
alias .4='cd ../../../../' # Go back 4 directory levels | |
alias .5='cd ../../../../../' # Go back 5 directory levels | |
alias .6='cd ../../../../../../' # Go back 6 directory levels | |
alias edit='code' # edit: Opens any file in sublime editor | |
alias f='open -a Finder ./' # f: Opens current directory in MacOS Finder | |
alias ~="cd ~" # ~: Go Home | |
alias c='clear' # c: Clear terminal display | |
#alias which='type -all' # which: Find executables | |
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths | |
alias show_options='shopt' # Show_options: display bash options settings | |
alias fix_stty='stty sane' # fix_stty: Restore terminal settings when screwed up | |
alias cic='set completion-ignore-case On' # cic: Make tab-completion case-insensitive | |
mcd () { mkdir -p "$1" && cd "$1"; } # mcd: Makes new Dir and jumps inside | |
trash () { command mv "$@" ~/.Trash ; } # trash: Moves a file to the MacOS trash | |
ql () { qlmanage -p "$*" >& /dev/null; } # ql: Opens any file in MacOS Quicklook Preview | |
alias DT='tee ~/Desktop/terminalOut.txt' # DT: Pipe content to file on MacOS Desktop | |
whode () {which $1 | xargs code;} # Get exe using `which` then edit with `code`` | |
# lr: Full Recursive Directory Listing | |
# ------------------------------------------ | |
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\''' | |
# mans: Search manpage given in agument '1' for term given in argument '2' (case insensitive) | |
# displays paginated result with colored search terms and two lines surrounding each hit. Example: mans mplayer codec | |
# -------------------------------------------------------------------- | |
mans () { | |
man $1 | grep -iC2 --color=always $2 | less | |
} | |
# showa: to remind yourself of an alias (given some part of it) | |
# ------------------------------------------------------------ | |
showa () { /usr/bin/grep --color=always -i -a1 $@ ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; } | |
zipf () { zip -r "$1".zip "$1" ; } # zipf: To create a ZIP archive of a folder | |
alias numFiles='echo $(ls -1 | wc -l)' # numFiles: Count of non-hidden files in current dir | |
alias make1mb='mkfile 1m ./1MB.dat' # make1mb: Creates a file of 1mb size (all zeros) | |
alias make5mb='mkfile 5m ./5MB.dat' # make5mb: Creates a file of 5mb size (all zeros) | |
alias make10mb='mkfile 10m ./10MB.dat' # make10mb: Creates a file of 10mb size (all zeros) | |
# extract: Extract most known archives with one command | |
# --------------------------------------------------------- | |
extract () { | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xjf $1 ;; | |
*.tar.gz) tar xzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar e $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xf $1 ;; | |
*.tbz2) tar xjf $1 ;; | |
*.tgz) tar xzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "'$1' cannot be extracted via extract()" ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
# ===================================================================================== | |
# SEARCHING | |
# ===================================================================================== | |
alias qfind="find . -name " # qfind: Quickly search for file | |
ff () { /usr/bin/find . -name "$@" ; } # ff: Find file under the current directory | |
ffs () { /usr/bin/find . -name "$@"'*' ; } # ffs: Find file whose name starts with a given string | |
ffe () { /usr/bin/find . -name *"$@" ; } # ffe: Find file whose name ends with a given string | |
hfind () { history | grep "$1"; } # hfind: Find a specific command in history output | |
# example: largefiles ~/ 100M (finds files >= 100 meg from home dir) | |
largefiles () {find "$1" -type f -size +"$2""$3" -exec ls -lh {} \; | awk '{ print $5 " :\t" $9 }'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment