Oh my Bash!!!
On this sub-page, I will share my favorite bash setup
Git graph
I use various source code control and I like git
!. Want to see the how code evolve and checking the log? This is my favorite alias:
alias gitgraph="git log --graph --date-order --date=format:'%d/%m/%y' --pretty=format:'%C(auto)%h%d %C(reset)%s %C(bold blue)%ce %C(reset)%C(green) (%cd)'"
Be careful
# ═══════════════════════════════════════ # Let be careful, ok? # ═══════════════════════════════════════ # interactive # -i prompt before overwrite # -v verbose alias rm='rm -i -v' alias mv='mv -i -v' alias cp='cp -i -v' alias ln='ln -i'
Proxy
This is how I set proxy on my terminal via bash. I have 2 function setproxy
and unsetproxy
. For example, Here I how I do to set proxy within my university network. Both function also will setup/reset my git config
## set proxy (BASH only not systemwide) function setproxy() { export NO_PROXY='localhost,127.0.0.0/8,::1,*.uthm.edu.my' export no_proxy='localhost,127.0.0.0/8,::1,*.uthm.edu.my' export {HTTP,HTTPS,FTP}_PROXY='http://proxy.uthm.edu.my:8080/' export {http,https,ftp}_proxy='http://proxy.uthm.edu.my:8080/' gsettings set org.gnome.system.proxy mode 'manual' gsettings set org.gnome.system.proxy.ftp host 'proxy.uthm.edu.my' gsettings set org.gnome.system.proxy.ftp port 8080 gsettings set org.gnome.system.proxy.https host 'proxy.uthm.edu.my' gsettings set org.gnome.system.proxy.https port 8080 gsettings set org.gnome.system.proxy.http host 'proxy.uthm.edu.my' gsettings set org.gnome.system.proxy.http port 8080 gnome-terminal -x bash -c "git config --global http.proxy \"proxy.uthm.edu.my:8080\"" echo -e "Proxy environment variable has been setup!" } function unsetproxy() { unset {HTTP,HTTPS,FTP}_PROXY unset {http,https,ftp}_proxy unset no_proxy unset NO_PROXY gsettings set org.gnome.system.proxy mode 'none' gnome-terminal -x bash -c "git config --global http.proxy \"\"" echo -e "Proxy environment variable removed." }
Weather report
I travelling a lot, I checking weather forecast from time to time
# ═══════════════════════════════════════ # Weather # ═══════════════════════════════════════ # usage : # weather simpang+renggam # weather ~wongnoi function weather { curl -s wttr.in/$1 }
This is how it look like:
$ curl -s wttr.in/kedah Weather report: kedah \ / Partly cloudy _ /"".-. 26..30 °C \_( ). ↙ 7 km/h /(___(__) 8 km 0.0 mm ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Tue 29 Dec ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ │ _ /"".-. 25..27 °C │ _ /"".-. 32..34 °C │ _ /"".-. 30..33 °C │ _ /"".-. 26..29 °C │ │ \_( ). ← 5-8 km/h │ \_( ). ↖ 3 km/h │ \_( ). → 5-6 km/h │ \_( ). ↑ 2-4 km/h │ │ /(___(__) 10 km │ /(___(__) 10 km │ /(___(__) 10 km │ /(___(__) 10 km │ │ 0.0 mm | 0% │ 0.0 mm | 0% │ 0.0 mm | 0% │ 0.0 mm | 0% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Wed 30 Dec ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Partly cloudy │ \ / Partly cloudy │ \ / Partly cloudy │ _`/"".-. Patchy rain po…│ │ _ /"".-. 25..27 °C │ _ /"".-. 31..34 °C │ _ /"".-. 29..33 °C │ ,\_( ). 26..28 °C │ │ \_( ). ↙ 4-6 km/h │ \_( ). ↖ 3 km/h │ \_( ). → 4-6 km/h │ /(___(__) ↑ 4-7 km/h │ │ /(___(__) 10 km │ /(___(__) 10 km │ /(___(__) 9 km │ ‘ ‘ ‘ ‘ 10 km │ │ 0.0 mm | 0% │ 0.0 mm | 0% │ 0.2 mm | 43% │ ‘ ‘ ‘ ‘ 0.4 mm | 26% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Thu 31 Dec ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Partly cloudy │ \ / Partly cloudy │ _`/"".-. Light rain sho…│ _`/"".-. Patchy rain po…│ │ _ /"".-. 24..27 °C │ _ /"".-. 29..32 °C │ ,\_( ). 28..31 °C │ ,\_( ). 24..26 °C │ │ \_( ). ↙ 5-9 km/h │ \_( ). ↙ 5 km/h │ /(___(__) ↓ 3-5 km/h │ /(___(__) ↙ 4-8 km/h │ │ /(___(__) 5 km │ /(___(__) 10 km │ ‘ ‘ ‘ ‘ 10 km │ ‘ ‘ ‘ ‘ 10 km │ │ 0.0 mm | 0% │ 0.0 mm | 0% │ ‘ ‘ ‘ ‘ 1.3 mm | 68% │ ‘ ‘ ‘ ‘ 0.2 mm | 64% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ Location: Kedah, Malaysia [5.9682875,100.6660103]
History
My history teacher said "Sejarah adalah penting dan kita akan belajar kesilapan, kesalahan daripada sejarah untuk ke arah yang lebih baik" which mean "History are important, we learned our mistake, fault from it and become better". Same goes to bash!
# ═══════════════════════════════════════ # Bash history # ═══════════════════════════════════════ export HISTSIZE=1000000 # remember the last 100000 commands export HISTFILESIZE=100000 # start truncating commands after 100000 lines export HISTCONTROL='ignoreboth' # ignoreboth is shorthand for ignorespace and ignoredups export HISTIGNORE='&:ls:[bf]g:exit' export HISTTIMEFORMAT="%Y/%m/%d %T " # The following line ensures that history logs screen commands as well shopt -s histappend # This line makes the history file to be rewritten and reread at each bash prompt PROMPT_COMMAND="$PROMPT_COMMAND;history -a; history -n" set cmdhist
Extracting archive file
Memorize command how to extract arch file is easy but the list getting bigger now since there is always new compression algorithm comes in. So let just use extract
to extract everything she found!
# ═══════════════════════════════════════ # Archive # ═══════════════════════════════════════ # 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 }
Dmesg for human
Are you checking kernel ring buffer? If you are human then you need this
alias dmesg="dmesg --human"
The output will be much better
> Thu Dec 31 07:39:59 AM +08 2020 robbi@r0x: pts/0: /home/robbi 10 files 180Kb └─ $ dmesg --human | tail [Dec30 21:53] e1000: enp0s3 NIC Link is Down [ +2.048291] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [Dec31 04:18] e1000: enp0s3 NIC Link is Down [ +2.048495] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [Dec31 07:02] e1000: enp0s3 NIC Link is Down [ +4.096272] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [Dec31 07:30] e1000: enp0s3 NIC Link is Down [ +1.851533] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [ +32.772380] e1000: enp0s3 NIC Link is Down [Dec31 07:31] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX > Thu Dec 31 07:40:28 AM +08 2020 robbi@r0x: pts/0: /home/robbi 10 files 180Kb └─ $ dmesg | tail [68638.379954] e1000: enp0s3 NIC Link is Down [68640.428245] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [91763.772872] e1000: enp0s3 NIC Link is Down [91765.821367] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [101623.665194] e1000: enp0s3 NIC Link is Down [101627.761466] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [103273.511984] e1000: enp0s3 NIC Link is Down [103275.363517] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX [103308.135897] e1000: enp0s3 NIC Link is Down [103312.234112] e1000: enp0s3 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX