Last active
April 21, 2021 00:49
-
-
Save vipyne/129e4c3ce0f684e863048bc54b2b72c6 to your computer and use it in GitHub Desktop.
stupid bash tricks - macos / bsd flavored
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
##### PLAY ALL THE SOUNDS ##### | |
## https://ss64.com/osx/afplay.html | |
musicafast () | |
{ | |
echo "find / -type f -name "*.aif" -o -name "*.mp3" 2>/dev/null |xargs -I % afplay % -r 7" | |
find / -type f -name "*.aif" -o -name "*.mp3" 2>/dev/null |xargs -I % afplay % -r 7 | |
} | |
##### ANNOY SOMEONE ELSE ##### | |
$ export PS1=$PS1'\a' | |
export PS2='\[\033[0;36m\]_more\[\033[0;34m\] >\[\033[0m\] ' | |
##### RAINBOW ##### (thanks @lritter) | |
rainbow() | |
{ | |
digits=$(date +%s) | |
random="${digits: -2}" | |
default_offset="$random"+3*13 | |
default_stride="$random"+1 | |
offset="${1:-$default_offset}" | |
stride="${2:-$default_stride}" | |
# for 9 lines in a window: | |
for l in $(seq 9); do | |
c=$(echo "define abs(i) {if (i < 0) return (-i); return (i) }; (abs(215-(${l}*${stride})+${offset}) % 215) + 16" | bc) | |
printf "\x1b[48;5;${c}m\n" | |
done | |
tput sgr0 | |
printf "\n" | |
} | |
##### RAINBOW WINDOW ##### (thanks @lritter) | |
rainbows() | |
{ | |
digits=$(date +%s) | |
random="${digits: -2}" | |
default_offset="$random"+3*13 | |
default_stride="$random"+1 | |
offset="${1:-$default_offset}" | |
stride="${2:-$default_stride}" | |
## for all the lines in a window: | |
for l in $(seq $(tput lines)); do | |
c=$(echo "define abs(i) {if (i < 0) return (-i); return (i) }; (abs(215-(${l}*${stride})+${offset}) % 215) + 16" | bc) | |
printf "\x1b[48;5;${c}m\n" | |
done | |
tput sgr0 | |
printf "\n" | |
} | |
##### CHECK SOUND ##### | |
## https://ss64.com/osx/afplay.html | |
chk () | |
{ | |
$* | |
if [ $? -eq 0 ] | |
then | |
# success, good sound | |
say success | |
afplay /Music/Kanye\ West/Yandhi/07\ Last\ Name\ \(Instrumental\ Interlude\).mp3 -t 11.6 -r 3 -v 0.3 | |
else | |
# fail, bad sound | |
say failure | |
afplay /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/test/Sine-1000Hz-300ms.aif | |
fi | |
## success ex | |
# chk echo | |
## failure ex | |
# chk eval [[ 9 -eq 99 ]] | |
} | |
##### MK EXECUTABLE ##### (thanks @bleveque) | |
function touche() { | |
touch $1 | |
chmod 755 $1 | |
} | |
##### FRI-SAY ##### (thanks @bleveque) | |
say "$(curl -s -X GET 'https://gist.githubusercontent.com/vipyne/632e6a8614a4d3c8068bdb1996b5c131/raw/89414d81f9d7c64686cdc8de00e744dda78b2944/FRIDAY' | sed 's/\\n/ /g')" | |
## inspired by: | |
# function runProductionDeploy() { | |
# runDeploy staging production $install_dependencies | |
# if [ $day_of_week -eq 5 ]; then | |
# echo "Here's a song while you continue with your friday!" | |
# say "$(curl -s -X GET https://private-anon-fc483754f2-lyricsovh.apiary-proxy.com/v1/Rebecca%20Black/Friday | sed 's/\\n/ /g')" & # wrong private hash | |
# fi | |
# } | |
##### CHANGE TAB TITLE ##### | |
t () | |
{ | |
TITLE=$@; | |
TITLE_CAP=$(echo "$TITLE" | tr '[:lower:]' '[:upper:]'); | |
ttty=$(echo $(tty) | sed -e 's/\/[a-zA-Z]*//g') | |
echo -en "\033]0;|| $ttty $TITLE_CAP \a "; | |
} | |
t $(basename $(pwd)) | |
##### STAR TAB TITLE ##### | |
# EMOJI = ππβ€οΈππ§‘π€π | |
ts () | |
{ | |
EMOJIS=(π π€ π π 𧑠π β€οΈ) | |
ARGS="$@" | |
TITLE="" | |
BOOL=1 | |
for i in $ARGS;do | |
if [ $BOOL -eq 1 ];then | |
BOOL=1234; | |
continue; | |
fi; | |
TITLE+="$i" | |
TITLE+=" " | |
done | |
TITLE_CAP=$(echo "$TITLE" | tr '[:lower:]' '[:upper:]'); | |
STAR="β${EMOJIS[$1]}"; | |
echo -en "\033]0;|| $STAR $TITLE_CAP $STAR ||\a "; | |
} | |
colorz () #https://raymii.org/s/snippets/Bash_Bits_Add_Color_Output_To_Your_Scripts.html | |
{ | |
x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; | |
} | |
ansi() #http://wiki.bash-hackers.org/scripting/terminalcodes | |
{ | |
for a in 0 1 4 5 7; do | |
echo "a=$a " | |
for (( f=0; f<=9; f++ )) ; do | |
for (( b=0; b<=9; b++ )) ; do | |
#echo -ne "f=$f b=$b" | |
echo -ne "\\033[${a};3${f};4${b}m" | |
echo -ne "\\\\\\\\033[${a};3${f};4${b}m" | |
echo -ne "\\033[0m " | |
done | |
echo | |
done | |
echo | |
done | |
echo | |
} | |
##### fun aliases | |
alias woman='man' | |
alias dog='cat' | |
alias moon='echo "curl wttr.in/Moon" && curl wttr.in/Moon' | |
export CLICOLOR=1 | |
# https://www.cyberciti.biz/faq/apple-mac-osx-terminal-color-ls-output-option/ | |
alias ls='LSCOLORS=aggxcxcxCxegedabagacad ls -Galh' | |
alias nls='$(which ls)' | |
##### because touchbars are the worst... | |
alias futb='sudo pkill TouchBarServer' | |
alias ndiff="git diff -- . ':!package-lock.json'" | |
alias listscripts="sed -n '/\"scripts\": {/,/\}\,/{//!p;}' package.json" | |
##### just stupid | |
brew install sl | |
brew install lolcat | |
brew install cowsay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment