Created
February 8, 2017 09:59
-
-
Save tayvano/a18098a8501fdfcc56711cb38a7d4ab7 to your computer and use it in GitHub Desktop.
This file contains 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
# ----------------------------- | |
# 2. MAKE TERMINAL BETTER | |
# ----------------------------- | |
alias cp='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 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='open -a Sublime\ Text ./' # edit: Opens any file in sublime editor | |
alias f='open -a Finder ./' # f: Opens current directory in MacOS Finder | |
alias ~="cd ~" # ~: Go Home | |
alias copy="tr -d '\n' | pbcopy" | |
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 | |
alias pushlive='git subtree push --prefix dist origin gh-pages' | |
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update; sudo gem cleanup' | |
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder" | |
alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend" | |
# lr: Full Recursive Directory Listing | |
# ------------------------------------------ | |
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less' | |
# Usage: compresspdf [input file] [screen*|ebook|printer|prepress] | |
compresspdf() { | |
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/${1:-"ebook"} -dCompatibilityLevel=1.4 -sOutputFile="${file%.pdf}-small.pdf" "$file" | |
} | |
# Usage: compresspdfs | |
compresspdfs() { | |
for file in *.pdf | |
do | |
gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/${1:-"screen"} -dCompatibilityLevel=1.4 -sOutputFile="${file%.pdf}-small.pdf" "$file" | |
echo $file is compressed | |
done | |
} | |
# Usage: convertflv | |
# requires ffmpeg | |
convertflv() { | |
for file in *.mp4 | |
do | |
ffmpeg -i $file -ar 44100 -c:a libmp3lame -f flv ${file%.mp4}.flv | |
echo FLV: $file is converted | |
done | |
} | |
# Usage: convertogv | |
# requires ffmpeg | |
convertogv() { | |
for file in *.mp4 | |
do | |
ffmpeg -i $file -c:v libtheora -b:v 2000k -c:a libvorbis ${file%.mp4}.ogv | |
echo OGV: $file is converted | |
done | |
} | |
# Usage: convertwebm | |
# requires ffmpeg | |
convertwebm() { | |
for file in *.mp4 | |
do | |
ffmpeg -i $file -c:v libvpx -b:v 2000k -c:a libvorbis ${file%.mp4}.webm | |
echo WEBM: $file is converted | |
done | |
} | |
# Usage: convertmp4 | |
# requires ffmpeg | |
convertmp4() { | |
for file in *.mp4 | |
do | |
ffmpeg -i $file -c:v h264 -b:v 2000k ${file%.mp4}-small.mp4 | |
echo MP4: $file is converted | |
done | |
} | |
# Usage: compressvideos | |
# requires ffmpeg | |
compressvideos() { | |
for file in *.mp4 | |
do | |
ffmpeg -i $file -c:v h264 -b:v 2000k ${file%.mp4}-small.mp4 | |
echo MP4: $file is converted | |
ffmpeg -i $file -ar 44100 -c:a libmp3lame -f flv ${file%.mp4}.flv | |
echo FLV: $file is converted | |
ffmpeg -i $file -c:v libtheora -b:v 2000k -c:a libvorbis ${file%.mp4}.ogv | |
echo OGV: $file is converted | |
ffmpeg -i $file -c:v libvpx -b:v 2000k -c:a libvorbis ${file%.mp4}.webm | |
echo WEBM: $file is converted | |
done | |
} | |
# Usage: compressimgs | |
# requires imageoptim | |
# requires imagemagick | |
compressimgs() { | |
_size="${1:-1600}" | |
_dir="${2:-${PWD}}" | |
_files="$( find "$_dir" \( -name "*.jpg" -o -name "*.png" -o -name "*.jpeg" -o -name "*.gif" \) )" | |
for f in "$_files" ; do | |
mogrify -resize $_size"x"$_size">" -units PixelsPerInch -density 72 -verbose $f | |
done | |
imageoptim --directory "$_dir" | |
} | |
# Usage: imageopt | |
# requires imageoptim | |
imageopt() { | |
_dir="${1:-${PWD}}" | |
imageoptim --directory "$_dir" | |
} | |
# ------------------------------- | |
# 3. FILE AND FOLDER MANAGEMENT | |
# ------------------------------- | |
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 | |
# cdf: 'Cd's to frontmost window of MacOS Finder | |
# ------------------------------------------------------ | |
cdf () { | |
currFolderPath=$( /usr/bin/osascript <<EOT | |
tell application "Finder" | |
try | |
set currFolder to (folder of the front window as alias) | |
on error | |
set currFolder to (path to desktop folder as alias) | |
end try | |
POSIX path of currFolder | |
end tell | |
EOT | |
) | |
echo "cd to \"$currFolderPath\"" | |
cd "$currFolderPath" | |
} | |
# extract: Extract most know 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 | |
} | |
# --------------------------------------- | |
# 7. SYSTEMS OPERATIONS & INFORMATION | |
# --------------------------------------- | |
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl; sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'" | |
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete" | |
alias showHidden='defaults write com.apple.finder ShowAllFiles TRUE' | |
alias hideHidden='defaults write com.apple.finder ShowAllFiles FALSE' | |
alias cleanupLS="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder" | |
. ~/.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment