Last active
December 16, 2019 16:39
-
-
Save MarcAlx/a7df50fd6e383e9818f2ddb9df886d07 to your computer and use it in GitHub Desktop.
macOS bashrc
This file contains hidden or 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
# Here's my macOS bashrc | |
# /!\ it may override some existing commands like 'w' | |
# | |
# To use it : | |
# | |
# Put the following line inside ~/.bash_profile : | |
# [[ -s ~/.bashrc ]] && source ~/.bashrc | |
# | |
# Then create ~/.bashrc and put the content of this file in it. | |
#do git status | |
alias s='git status' | |
#do git branch | |
alias b='git branch' | |
#custom cd display content of the folder | |
function cd { | |
builtin cd "$@" | |
#display current path in red | |
echo -e "\033[0;31m" | |
pwd | |
echo -e "\033[0m" | |
ls -Ga | |
printf "\n" | |
#if there's a git | |
if [ -e ".git" ] | |
then | |
#display git title in blue | |
printf "\n\033[0;34m-- git --\033[0m\n" | |
b | |
printf "\n" | |
git status --short | |
printf "\n" | |
fi | |
} | |
#tells which app use given port | |
function wp { | |
if [[ "$#" -eq "1" ]]; then | |
sudo lsof -i :$1 | |
fi | |
} | |
#uglify given string | |
function u { | |
if [[ "$#" -eq "1" ]]; then | |
res="" | |
input=$1 | |
for (( i=0; i<${#input}; i++ )); do | |
tmp=${input:$i:1} | |
if [ $((i%2)) -eq 0 ]; | |
then | |
res+=$(echo "$tmp" | tr '[:upper:]' '[:lower:]') | |
else | |
res+=$(echo "$tmp" | tr '[:lower:]' '[:upper:]') | |
fi | |
done | |
echo $res | |
fi | |
} | |
#Descripe proved parameter (mean't to pretty print folder content) | |
function desc() { | |
if [[ "$#" -eq "0" ]]; then | |
tmp="$(pwd)" | |
desc $tmp 0 | |
elif [[ "$#" -eq "1" ]]; then | |
desc $1 0 | |
else | |
local indent=$2; | |
spaces="" | |
if [[ "$indent" -ne "0" ]]; then | |
for ((i=0;i<=indent;i++)) | |
do | |
spaces="${spaces} " | |
done | |
fi | |
if [[ -d "$1" ]]; then | |
echo $spaces"↳ 📂 "$(basename $1) | |
indent=$((indent+1)) | |
#set IFS to process folder with space in their name | |
SAVEIFS=$IFS | |
IFS=$(echo -en "\n\b") | |
for f in $1/* | |
do | |
desc $f $((indent+1)) | |
done | |
# restore $IFS | |
IFS=$SAVEIFS | |
elif [[ -f "$1" ]]; then | |
echo $spaces"↳ 📄 "$(basename $1) | |
fi | |
fi | |
} | |
#alias for ls -la | |
alias ll='ls -la' | |
#launch cd . tell where you are | |
alias w='cd .' | |
#launch cd .. go to parent folder | |
alias p='cd ..' | |
#alias for clean | |
alias c='clear' | |
#clear screen and display what's inside | |
alias cw='c && w' | |
#clear screen and back to home | |
alias ch='c && h' | |
#back to home | |
alias h='cd' | |
#alias to pretty printed date | |
function d { | |
date +"%T - %A - %D" | |
} | |
#go to download folder | |
alias cdd='cd ~/Downloads' | |
#go to workspace | |
alias cdw='cd ~/Documents/workspace' | |
#go to / | |
alias cdr='cd /' | |
#go to /Applications OSX only | |
alias cda='cd /Applications' | |
#give the size of an element usage : sizeof <element name> | |
function sizeof() { | |
if [[ ! -z "$1" ]]; then | |
du -hcs "$1" | |
fi | |
} | |
#OSX only open current folder in finder | |
function o() { | |
if [ "$#" -eq "0" ] | |
then | |
open . | |
else | |
open "$@" | |
fi | |
} | |
#give information about network interface | |
alias ni='ifconfig' | |
#launch a web server python on port specified else 8000 | |
function serve() { | |
if [ "$#" -eq "0" ] | |
then | |
python -m SimpleHTTPServer 8000 | |
else | |
python -m SimpleHTTPServer "$@" | |
fi | |
} | |
#give stat about the system | |
function stat() { | |
ps -A -o %cpu | awk '{s+=$1} END {print "CPU Usage : " s "%"}' | |
printf "\n" | |
top -l 1 -s 0 | awk '/Processes/' | |
printf "\n" | |
top -l 1 -s 0 | awk '/PhysMem/' | |
printf "\n" | |
df -h / | |
printf "\n" | |
} | |
#do a chmod 777 above the given file | |
function all() { | |
if [[ ! -z "$1" ]]; then | |
chmod 777 "$1" | |
fi | |
} | |
#give information about hardware | |
function hinfo() { | |
/usr/sbin/system_profiler SPHardwareDataType | |
} | |
#create a file of the given name | |
alias mkf='touch' | |
#create a folder of the given name | |
alias mkd='mkdir' | |
#delete file or folder of the given name, alias for rm -rf | |
alias del='sudo rm -rf' | |
###open a website | |
function www() { | |
if [[ ! -z "$1" ]]; then | |
if [[ "$1" != http://* ]]; then | |
open "http://$1" | |
else | |
open "$1" | |
fi | |
fi | |
} | |
#run a file, makes it runnable it not runnable | |
function run(){ | |
if [[ ! -z "$1" ]]; then | |
if [[ -x "$1" ]] | |
then | |
./"$1" | |
else | |
chmod +x "$1" | |
./"$1" | |
fi | |
fi | |
} | |
#untar file | |
alias untar='tar -zxvf ' | |
#get sha | |
alias sha='shasum -a 256 ' | |
#get your external ip | |
alias ipe='curl ipinfo.io/ip' | |
#get your internal ip | |
alias ip='ipconfig getifaddr en0' | |
#list all commands introduced by bashrc | |
function ?() { | |
printf "\n" | |
printf "\x1b[1m--- .bashrc shortcuts ---\e[0m \n" | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : do the following commands : 'cd @;pwd;ls -Ga;git branch (with coloration)'\n" cd | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : back to home ~\n" h | |
printf "\x1b[1m%7s\e[0m : go to /\n" cdr | |
printf "\x1b[1m%7s\e[0m : go to /Applications\n" cda | |
printf "\x1b[1m%7s\e[0m : go to parent directory\n" p | |
printf "\x1b[1m%7s\e[0m : go to ~/Downloads\n" cdd | |
printf "\x1b[1m%7s\e[0m : go to ~/Documents/workspace\n" cdw | |
printf "\x1b[1m%7s\e[0m : do 'cd .' (with .bashrc cd)\n" w | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : alias for 'clear'\n" c | |
printf "\x1b[1m%7s\e[0m : clear screen and back to home\n" ch | |
printf "\x1b[1m%7s\e[0m : clear screen and display what's inside folder\n" cw | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : alias for 'open', open current folder in finder without args\n" o | |
printf "\x1b[1m%7s\e[0m : print date\n" d | |
printf "\x1b[1m%7s\e[0m : open a website in default browser, usage : 'www URL'\n" www | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : Uglify given strings, usage : 'u \"hello\"' will produce \"hElLo\"\n" u | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : alias for 'ls -la'\n" ll | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : alias for 'git status'\n" s | |
printf "\x1b[1m%7s\e[0m : alias for 'git branch'\n" b | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : create a file of the given name, usage : 'mkf FILENAME'\n" mkf | |
printf "\x1b[1m%7s\e[0m : create a folder of the given name, usage : 'mkd FOLDERNAME'\n" mkd | |
printf "\x1b[1m%7s\e[0m : do a 'chmod 777' above given element, usage : 'all FILENAME'\n" all | |
printf "\x1b[1m%7s\e[0m : run the given element, do 'chmod+x' if not runnable, usage : 'run FILENAME'\n" run | |
printf "\x1b[1m%7s\e[0m : give the size of an element, usage : 'sizeof ELEMENT_NAME'\n" sizeof | |
printf "\x1b[1m%7s\e[0m : describe folder content, usage : 'desc FOLDERNAME'\n" desc | |
printf "\x1b[1m%7s\e[0m : alias for 'rm -rf', usage del FILENAME_OR_FOLDERNAME\n" del | |
printf "\x1b[1m%7s\e[0m : untar a file\n" untar | |
printf "\x1b[1m%7s\e[0m : get sha of a file\n" sha | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : alias for 'python -m SimpleHTTPServer', launch on port 8000 without args\n" serve | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : give information about the system'\n" stat | |
printf "\x1b[1m%7s\e[0m : give information about the hardware'\n" hinfo | |
printf "\x1b[1m%7s\e[0m : give information about the network interface'\n" ni | |
printf "\x1b[1m%7s\e[0m : tells which app use given port, usage : 'wp 3000'\n" wp | |
printf "\x1b[1m%7s\e[0m : get your external ip address'\n" ipe | |
printf "\x1b[1m%7s\e[0m : get your internal ip address'\n" ip | |
printf "\n" | |
printf "\x1b[1m%7s\e[0m : print this help menu\n" ? | |
printf "\n" | |
} | |
#display current folder content, once console/tab is open | |
printf "type ? to list custom .bashrc commands" | |
w | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment