Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.46 KB | None | 0 0
  1. # ---------------------------------------------------------------------------
  2. #
  3. # Description: This file holds all my BASH configurations and aliases
  4. #
  5. # Sections:
  6. # 1. Environment Configuration
  7. # 2. Make Terminal Better (remapping defaults and adding functionality)
  8. # 3. File and Folder Management
  9. # 4. Searching
  10. # 5. Process Management
  11. # 6. Networking
  12. # 7. System Operations & Information
  13. # 8. Web Development
  14. # 9. Reminders & Notes
  15. #
  16. # ---------------------------------------------------------------------------
  17. function gi() { curl -L -s https://www.gitignore.io/api/$@ ;}
  18. function deploy() { fab $@ deploy;}
  19. function rm () { /bin/rm -i $@ ;}
  20. function kill9() { ps auxww | grep $@ | awk '{print $2}' | xargs kill -9 ;}
  21. function httpserver() { python -m SimpleHTTPServer $@ && open "http://127.0.0.1:$@";}
  22. function cat() { pygmentize -g $@ ; }
  23. function cd() { cd $@ && ls ; }
  24. function weather() { curl wttr.in/$@ ; }
  25. function heroku_db() { heroku config:get DATABASE_URL --app $@ | xargs open;}
  26. # -------------------------------
  27. # SERVERS
  28. # -------------------------------
  29.  
  30.  
  31. # -------------------------------
  32. # WORKSPACES / PROJECTS
  33. # -------------------------------
  34.  
  35. # alias project="cd /Users/PycharmProjects/youbl-admin/frontend/ && git pull && sudo npm install && bower install && gulp serve"
  36.  
  37. # -------------------------------
  38. # ALIASES
  39. # -------------------------------
  40.  
  41. alias python_package='cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git'
  42. alias e='. env/bin/activate'
  43. alias style='tox -e check-isort,check-flake8'
  44. alias v='vim'
  45. alias vrc='editor ~/.vimrc'
  46. alias vi='vim'
  47. alias ve='. .ve/bin/activate'
  48. alias lessc='/usr/local/bin/lessc'
  49. alias ga='g++ *.cpp && ./a.out'
  50. alias editor='vim'
  51. alias bash_profile='editor ~/.bash_profile && source ~/.bash_profile'
  52. alias rm="rm -i"
  53. alias speedtest='wget -O /dev/null http://speedtest.london.linode.com/100MB-london.bin'
  54. alias g='grep -nr'
  55. alias sopot='weather sopot'
  56. alias ascii_docs='man 7 ascii'
  57.  
  58. # Setting PATH for Python 3.4
  59. # The orginal version is saved in .bash_profile.pysave
  60. PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
  61. export PATH
  62. export PATH=/usr/local/bin:$PATH
  63. export PATH=/usr/local/bin/mongodb/bin/:$PATH
  64. export PATH=$PATH:/usr/local/sbin
  65. if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
  66.  
  67. # export GOPATH=~/go
  68. # export PATH=$PATH:$GOPATH/bin
  69.  
  70.  
  71. # GIT
  72. parse_git_branch() {
  73. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
  74. }
  75.  
  76. if [ -f `brew --prefix`/etc/bash_completion ]; then
  77. . `brew --prefix`/etc/bash_completion
  78. fi
  79.  
  80. # FZF IS ROCKSTAR
  81. fh() {
  82. eval $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
  83. }
  84.  
  85. fkill() {
  86. pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
  87.  
  88. if [ "x$pid" != "x" ]
  89. then
  90. kill -${1:-9} $pid
  91. fi
  92. }
  93.  
  94. fchrome() {
  95. local cols sep
  96. cols=$(( COLUMNS / 3 ))
  97. sep='{{::}}'
  98.  
  99. # Copy History DB to circumvent the lock
  100. # - See http://stackoverflow.com/questions/8936878 for the file path
  101. cp -f ~/Library/Application\ Support/Google/Chrome/Default/History /tmp/h
  102.  
  103. sqlite3 -separator $sep /tmp/h \
  104. "select substr(title, 1, $cols), url
  105. from urls order by last_visit_time desc" |
  106. awk -F $sep '{printf "%-'$cols's \x1b[36m%s\n", $1, $2}' |
  107. fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs open
  108. }
  109.  
  110. # COLORS
  111.  
  112.  
  113. # -------------------------------
  114. # 1. ENVIRONMENT CONFIGURATION
  115. # -------------------------------
  116.  
  117. # Change Prompt
  118. # ------------------------------------------------------------
  119. export PS1="________________________________________________________________________________\n| \u \n| \w \$(parse_git_branch) \n| => "
  120. export PS2="| => "
  121. export PROMPT_COMMAND="history -a;((\$SECONDS % 10==0 ))&&eval \"\$AA_P\";echo -en \"\$PVE\";" \
  122.  
  123. # Set Paths
  124. # ------------------------------------------------------------
  125. export PATH="$PATH:/usr/local/bin/"
  126. export PATH="/usr/local/git/bin:/sw/bin/:/usr/local/bin:/usr/local/:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
  127.  
  128. # POSTGRES
  129. export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
  130.  
  131. # Set Default Editor (change 'Nano' to the editor of your choice)
  132. # ------------------------------------------------------------
  133. export EDITOR=/usr/bin/nano
  134.  
  135. # Set default blocksize for ls, df, du
  136. # from this: http://hints.macworld.com/comment.php?mode=view&cid=24491
  137. # ------------------------------------------------------------
  138. export BLOCKSIZE=1k
  139.  
  140. # Add color to terminal
  141. # (this is all commented out as I use Mac Terminal Profiles)
  142. # from http://osxdaily.com/2012/02/21/add-color-to-the-terminal-in-mac-os-x/
  143. # ------------------------------------------------------------
  144. export CLICOLOR=1
  145.  
  146.  
  147.  
  148. # -----------------------------
  149. # 2. MAKE TERMINAL BETTER
  150. # -----------------------------
  151.  
  152. alias cp='cp -iv' # Preferred 'cp' implementation
  153. alias mv='mv -iv' # Preferred 'mv' implementation
  154. alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation
  155. alias l='ls -FGlAhp' # Preferred 'ls' implementation
  156. alias ls='ls -GFh' # Preferred 'ls' implementation
  157. alias less='less -FSRXc' # Preferred 'less' implementation
  158. cd() { builtin cd "$@"; ls; } # Always list directory contents upon 'cd'
  159. alias cd..='cd ../' # Go back 1 directory level (for fast typers)
  160. alias ..='cd ../' # Go back 1 directory level
  161. alias ...='cd ../../' # Go back 2 directory levels
  162. alias .3='cd ../../../' # Go back 3 directory levels
  163. alias .4='cd ../../../../' # Go back 4 directory levels
  164. alias .5='cd ../../../../../' # Go back 5 directory levels
  165. alias subl="/Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text"
  166. alias .6='cd ../../../../../../' # Go back 6 directory levels
  167. alias edit='editor $(fzf)' # edit: Opens any file in sublime editor
  168. alias f='open -a Finder ./' # f: Opens current directory in MacOS Finder
  169. alias ~="cd ~" # ~: Go Home
  170. alias c='clear' # c: Clear terminal display
  171. alias which='type -all' # which: Find executables
  172. alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths
  173. alias show_options='shopt' # Show_options: display bash options settings
  174. alias fix_stty='stty sane' # fix_stty: Restore terminal settings when screwed up
  175. alias cic='set completion-ignore-case On' # cic: Make tab-completion case-insensitive
  176. mcd () { mkdir -p "$1" && cd "$1"; } # mcd: Makes new Dir and jumps inside
  177. trash () { command mv "$@" ~/.Trash ; } # trash: Moves a file to the MacOS trash
  178. ql () { qlmanage -p "$*" >& /dev/null; } # ql: Opens any file in MacOS Quicklook Preview
  179. alias DT='tee ~/Desktop/terminalOut.txt' # DT: Pipe content to file on MacOS Desktop
  180.  
  181. # lr: Full Recursive Directory Listing
  182. # ------------------------------------------
  183. alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less'
  184.  
  185. # mans: Search manpage given in agument '1' for term given in argument '2' (case insensitive)
  186. # displays paginated result with colored search terms and two lines surrounding each hit. Example: mans mplayer codec
  187. # --------------------------------------------------------------------
  188. mans () {
  189. man $1 | grep -iC2 --color=always $2 | less
  190. }
  191.  
  192. # showa: to remind yourself of an alias (given some part of it)
  193. # ------------------------------------------------------------
  194. showa () { /usr/bin/grep --color=always -i -a1 $@ ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; }
  195.  
  196.  
  197. # -------------------------------
  198. # 3. FILE AND FOLDER MANAGEMENT
  199. # -------------------------------
  200.  
  201. zipf () { zip -r "$1".zip "$1" ; } # zipf: To create a ZIP archive of a folder
  202. alias numFiles='echo $(ls -1 | wc -l)' # numFiles: Count of non-hidden files in current dir
  203. alias make1mb='mkfile 1m ./1MB.dat' # make1mb: Creates a file of 1mb size (all zeros)
  204. alias make5mb='mkfile 5m ./5MB.dat' # make5mb: Creates a file of 5mb size (all zeros)
  205. alias make10mb='mkfile 10m ./10MB.dat' # make10mb: Creates a file of 10mb size (all zeros)
  206.  
  207. # cdf: 'Cd's to frontmost window of MacOS Finder
  208. # ------------------------------------------------------
  209. cdf () {
  210. currFolderPath=$( /usr/bin/osascript <<EOT
  211. tell application "Finder"
  212. try
  213. set currFolder to (folder of the front window as alias)
  214. on error
  215. set currFolder to (path to desktop folder as alias)
  216. end try
  217. POSIX path of currFolder
  218. end tell
  219. EOT
  220. )
  221. echo "cd to \"$currFolderPath\""
  222. cd "$currFolderPath"
  223. }
  224.  
  225. # extract: Extract most know archives with one command
  226. # ---------------------------------------------------------
  227. extract () {
  228. if [ -f $1 ] ; then
  229. case $1 in
  230. *.tar.bz2) tar xjf $1 ;;
  231. *.tar.gz) tar xzf $1 ;;
  232. *.bz2) bunzip2 $1 ;;
  233. *.rar) unrar e $1 ;;
  234. *.gz) gunzip $1 ;;
  235. *.tar) tar xf $1 ;;
  236. *.tbz2) tar xjf $1 ;;
  237. *.tgz) tar xzf $1 ;;
  238. *.zip) unzip $1 ;;
  239. *.Z) uncompress $1 ;;
  240. *.7z) 7z x $1 ;;
  241. *) echo "'$1' cannot be extracted via extract()" ;;
  242. esac
  243. else
  244. echo "'$1' is not a valid file"
  245. fi
  246. }
  247.  
  248.  
  249. # ---------------------------
  250. # 4. SEARCHING
  251. # ---------------------------
  252.  
  253. alias qfind="find . -name " # qfind: Quickly search for file
  254. ff () { /usr/bin/find . -name "$@" ; } # ff: Find file under the current directory
  255. ffs () { /usr/bin/find . -name "$@"'*' ; } # ffs: Find file whose name starts with a given string
  256. ffe () { /usr/bin/find . -name '*'"$@" ; } # ffe: Find file whose name ends with a given string
  257.  
  258. # spotlight: Search for a file using MacOS Spotlight's metadata
  259. # -----------------------------------------------------------
  260. spotlight () { mdfind "kMDItemDisplayName == '$@'wc"; }
  261.  
  262.  
  263. # ---------------------------
  264. # 5. PROCESS MANAGEMENT
  265. # ---------------------------
  266.  
  267. # findPid: find out the pid of a specified process
  268. # -----------------------------------------------------
  269. # Note that the command name can be specified via a regex
  270. # E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
  271. # Without the 'sudo' it will only find processes of the current user
  272. # -----------------------------------------------------
  273. findPid () { lsof -t -c "$@" ; }
  274.  
  275. # memHogsTop, memHogsPs: Find memory hogs
  276. # -----------------------------------------------------
  277. alias memHogsTop='top -l 1 -o rsize | head -20'
  278. alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'
  279.  
  280. # cpuHogs: Find CPU hogs
  281. # -----------------------------------------------------
  282. alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'
  283.  
  284. # topForever: Continual 'top' listing (every 10 seconds)
  285. # -----------------------------------------------------
  286. alias topForever='top -l 9999999 -s 10 -o cpu'
  287.  
  288. # ttop: Recommended 'top' invocation to minimize resources
  289. # ------------------------------------------------------------
  290. # Taken from this macosxhints article
  291. # http://www.macosxhints.com/article.php?story=20060816123853639
  292. # ------------------------------------------------------------
  293. alias ttop="top -R -F -s 10 -o rsize"
  294.  
  295. # my_ps: List processes owned by my user:
  296. # ------------------------------------------------------------
  297. my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }
  298.  
  299.  
  300. # ---------------------------
  301. # 6. NETWORKING
  302. # ---------------------------
  303.  
  304. alias myip='curl ipinfo.io' # myip: Public facing IP Address
  305. alias netCons='lsof -i' # netCons: Show all open TCP/IP sockets
  306. alias flushDNS='dscacheutil -flushcache; sudo killall -HUP mDNSResponder' # flushDNS: Flush out the DNS Cache
  307. alias lsock='sudo /usr/sbin/lsof -i -P' # lsock: Display open sockets
  308. alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP' # lsockU: Display only open UDP sockets
  309. alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP' # lsockT: Display only open TCP sockets
  310. alias ipInfo0='ipconfig getpacket en0' # ipInfo0: Get info on connections for en0
  311. alias ipInfo1='ipconfig getpacket en1' # ipInfo1: Get info on connections for en1
  312. alias openPorts='sudo lsof -i | grep LISTEN' # openPorts: All listening connections
  313. alias showBlocked='sudo ipfw list' # showBlocked: All ipfw rules inc/ blocked IPs
  314.  
  315. # ii: display useful host related informaton
  316. # -------------------------------------------------------------------
  317. ii() {
  318. echo -e "\nYou are logged on ${RED}$HOST"
  319. echo -e "\nAdditionnal information:$NC " ; uname -a
  320. echo -e "\n${RED}Users logged on:$NC " ; w -h
  321. echo -e "\n${RED}Current date :$NC " ; date
  322. echo -e "\n${RED}Machine stats :$NC " ; uptime
  323. echo -e "\n${RED}Current network location :$NC " ; scselect
  324. echo -e "\n${RED}Public facing IP Address :$NC " ;myip
  325. #echo -e "\n${RED}DNS Configuration:$NC " ; scutil --dns
  326. echo
  327. }
  328.  
  329.  
  330. # ---------------------------------------
  331. # 7. SYSTEMS OPERATIONS & INFORMATION
  332. # ---------------------------------------
  333.  
  334. alias mountReadWrite='/sbin/mount -uw /' # mountReadWrite: For use when booted into single-user
  335.  
  336. # cleanupDS: Recursively delete .DS_Store files
  337. # -------------------------------------------------------------------
  338. alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"
  339.  
  340. # finderShowHidden: Show hidden files in Finder
  341. # finderHideHidden: Hide hidden files in Finder
  342. # -------------------------------------------------------------------
  343. alias finderShowHidden='defaults write com.apple.finder ShowAllFiles TRUE'
  344. alias finderHideHidden='defaults write com.apple.finder ShowAllFiles FALSE'
  345.  
  346. # cleanupLS: Clean up LaunchServices to remove duplicates in the "Open With" menu
  347. # -----------------------------------------------------------------------------------
  348. alias cleanupLS="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"
  349.  
  350. # screensaverDesktop: Run a screensaver on the Desktop
  351. # -----------------------------------------------------------------------------------
  352. alias screensaverDesktop='/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background'
  353.  
  354. # ---------------------------------------
  355. # 8. WEB DEVELOPMENT
  356. # ---------------------------------------
  357.  
  358. alias apacheEdit='sudo edit /etc/httpd/httpd.conf' # apacheEdit: Edit httpd.conf
  359. alias apacheRestart='sudo apachectl graceful' # apacheRestart: Restart Apache
  360. alias editHosts='sudo edit /etc/hosts' # editHosts: Edit /etc/hosts file
  361. alias herr='tail /var/log/httpd/error_log' # herr: Tails HTTP error logs
  362. alias apacheLogs="less +F /var/log/apache2/error_log" # Apachelogs: Shows apache error logs
  363. alias webserver='python -m SimpleHTTPServer'
  364. httpHeaders () { /usr/bin/curl -I -L $@ ; } # httpHeaders: Grabs headers from web page
  365.  
  366. # httpDebug: Download a web page and show info on what took time
  367. # -------------------------------------------------------------------
  368. httpDebug () { /usr/bin/curl $@ -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement