Last active
June 24, 2022 09:01
-
-
Save ovntatar/f6b79e2412b48f901bf9bfa864efc341 to your computer and use it in GitHub Desktop.
.bashrc
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
# Skip this config if we aren't in bash | |
[[ -n "${BASH_VERSION}" ]] || return | |
# ~/.bashrc: executed by bash(1) for non-login shells. | |
# .see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# If running non interactively, do nothing | |
######################################################## | |
#|# Preamble # | |
######################################################## | |
[ -z "$PS1" ] && return | |
# Determine platform first | |
case "$OSTYPE" in | |
solaris*) echo "SOLARIS" ;; | |
darwin*) echo "OSX" ;; | |
linux*) echo "LINUX" ;; | |
bsd*) echo "BSD" ;; | |
msys*) echo "WINDOWS" ;; | |
*) echo "unknown: $OSTYPE" ;; | |
esac | |
export HISTFILE="$HOME/.bash_history-$(hostname -s)" | |
export HISTTIMEFORMAT="%h/%d-%H:%M:%S " | |
export HISTSIZE= | |
export HISTFILESIZE= | |
chmod 700 $HISTFILE | |
function mysh_covert_date2epoch() { | |
#date -d "2018-01-08 14:45:00" +%s | |
#date -jf "%Y-%m-%d %H:%M:%S" "2018-01-08 14:45:00" +%s | |
[ "$OSTYPE" == "linux" ] && date -d "$1" +%s | |
[ "$OSTYPE" =~ "darvin" ] && date -jf "%Y-%m-%d %H:%M:%S" "$1" +%s | |
} | |
function mysh_covert_epoch2date() { | |
echo "$1" | perl -e 'print localtime(<>) . "\n"' | |
} | |
function mysh_urlescape() { | |
perl -MURI::Escape -le 'print uri_escape($1)' | |
} | |
function mysh_urlunescape() { | |
perl -MURI::Escape -le 'print uri_unescape($1)' | |
} | |
function mysh_htmlenc() { | |
perl -MHTML::Entities -le 'print encode_entities($1)' | |
} | |
function mysh_htmldec() { | |
perl -MHTML::Entities -le 'print decode_entities($1)' | |
} | |
function mysh_todo() { | |
echo "mysh_todo <add|close|del> <id> <message>" | |
file="$HOME/TODO.txt" | |
[ ! -f $file ] && touch $file | |
list_tasks(){ | |
cat $file | |
} | |
[ "$1" == "add" ] && echo "$2 = $3 = OPEN" >> $file && list_tasks | |
[ "$1" == "close" ] && sed -i -e "/$2/ s/OPEN/CLOSED/" $file && list_tasks | |
[ "$1" == "del" ] && sed -i -e "/$2/d" $file && list_tasks | |
} | |
function mysh_genpw() { | |
perl -E '@vals = split "", "0x1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-?!@^&*()"; $_ % 2 == 0 ? print $vals[ rand($#vals) ] : print fc $vals[ rand($#vals) ] for 0 .. 24; say;' | |
} | |
function mysh_compare_dirs() { | |
diff --brief --recursive "$1" "$2" | |
} | |
function mysh_copy_site() { | |
local domain=$(echo "$@" | awk -F/ '{print $3}') | |
wget --recursive --page-requisites --html-extension --convert-links --domains "$domain" --no-parent "$@" | |
} | |
function mysh_roll_back() { | |
git reset --hard $1 | |
git push -f | |
} | |
function mysh_kill_prog() { | |
kill $(ps aux | grep "$1" | awk '{print $2}') | |
} | |
function mysh_replace_rec() { | |
# $1 = OLD | |
# $2 = NEW | |
perl -p -i -e 's/$1/$2/g' `grep -rl "$1" .` | |
} | |
function mysh_githelp() { | |
curl https://gist.githubusercontent.com/ovntatar/c42da4bfcbd3edcfd9997d45754cfd69/raw/e1c37619cb952d5b45595fa0d5bb8c025bacc2fa/git-cli-overview.txt | |
} | |
function mysh_base64enc() { | |
# Base64 encode a string | |
perl -MMIME::Base64 -e 'print encode_base64("$1")' | |
} | |
function mysh_base64dec() { | |
perl -MMIME::Base64 -le 'print decode_base64("$1")' | |
} | |
function mysh_urlencode() { | |
old_lc_collate=$LC_COLLATE | |
LC_COLLATE=C | |
local length="${#1}" | |
for (( i = 0; i < length; i++ )); do | |
local c="${1:i:1}" | |
case $c in | |
[a-zA-Z0-9.~_-]) printf "$c" ;; | |
*) printf '%%%02X' "'$c" ;; | |
esac | |
done | |
LC_COLLATE=$old_lc_collate | |
} | |
function mysh_urldecode() { | |
local url_encoded="${1//+/ }" | |
printf '%b' "${url_encoded//%/\\x}" | |
} | |
function mysh_verifycert() { | |
openssl verify -verbose -CAfile <(cat "$2") "$1" | |
} | |
function mysh_lazygit() { | |
git add . | |
git commit -a -m "$1" | |
git push | |
} | |
function mysh_hist() { | |
history | grep "$1" | |
} | |
# When in a git repo, this method is used to determine the current branch | |
function mysh_parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
PROMPT_COMMAND=__prompt_command # Function to generate PS1 after CMDs | |
__prompt_command() { | |
local EXIT="$?" # This needs to be first | |
PS1="" | |
local RCol='\[\e[0m\]' | |
local Red='\[\e[0;31m\]' | |
local Gre='\[\e[0;32m\]' | |
local BYel='\[\e[1;33m\]' | |
local BBlu='\[\e[1;34m\]' | |
local Pur='\[\e[0;35m\]' | |
if [ $EXIT != 0 ]; then | |
PS1+="${Red}\u${RCol}" # Add red if exit code non 0 | |
else | |
PS1+="${Gre}\u${RCol}" | |
fi | |
PS1+="${RCol}@${BBlu}\h ${Pur}\W${BYel}$(mysh_parse_git_branch)${RCol}" | |
} | |
function mysh_cmdfu(){ | |
curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; | |
} | |
function mysh_hoctal_check() { | |
cat $1 | od -a -c | |
} | |
alias vi='vim -b' | |
alias grep='grep --color' | |
alias gi='grep -ri' | |
alias gr='grep -rl' | |
alias g='grep -i' # Case insensitive grep | |
alias f='find . -iname' | |
alias top='top -o cpu' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment