From Fedora Project Wiki
(weather forecast)
Line 117: Line 117:
 
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
 
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
 
Location: Kedah, Malaysia [5.9682875,100.6660103]
 
Location: Kedah, Malaysia [5.9682875,100.6660103]
 +
</pre>
  
 +
==== 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!
 +
<pre>
 +
# ═══════════════════════════════════════
 +
# 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
 
</pre>
 
</pre>

Revision as of 20:40, 28 December 2020

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)'"

GyVv3R.png

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 to 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