learnbyexample, 7 months ago <span style="color:#62a35c;">alias </span><span style="font-weight:bold;color:#795da3;">a</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">'alias' </span><span style="color:#323232;"> </span><span style="color:#323232;">a c=</span><span style="color:#183691;">'clear' </span><span style="color:#323232;">a p=</span><span style="color:#183691;">'pwd' </span><span style="color:#323232;">a e=</span><span style="color:#183691;">'exit' </span><span style="color:#323232;">a q=</span><span style="color:#183691;">'exit' </span><span style="color:#323232;"> </span><span style="color:#323232;">a h=</span><span style="color:#183691;">'history | tail -n20' </span><span style="font-style:italic;color:#969896;"># turn off history, use 'set -o history' to turn it on again </span><span style="color:#323232;">a so=</span><span style="color:#183691;">'set +o history' </span><span style="color:#323232;"> </span><span style="color:#323232;">a b1=</span><span style="color:#183691;">'cd ../' </span><span style="color:#323232;">a b2=</span><span style="color:#183691;">'cd ../../' </span><span style="color:#323232;">a b3=</span><span style="color:#183691;">'cd ../../../' </span><span style="color:#323232;">a b4=</span><span style="color:#183691;">'cd ../../../../' </span><span style="color:#323232;">a b5=</span><span style="color:#183691;">'cd ../../../../../' </span><span style="color:#323232;"> </span><span style="color:#323232;">a ls=</span><span style="color:#183691;">'ls --color=auto' </span><span style="color:#323232;">a l=</span><span style="color:#183691;">'ls -ltrhG' </span><span style="color:#323232;">a la=</span><span style="color:#183691;">'l -A' </span><span style="color:#323232;">a vi=</span><span style="color:#183691;">'gvim' </span><span style="color:#323232;">a grep=</span><span style="color:#183691;">'grep --color=auto' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># open and source aliases </span><span style="color:#323232;">a oa=</span><span style="color:#183691;">'vi ~/.bash_aliases' </span><span style="color:#323232;">a sa=</span><span style="color:#183691;">'source ~/.bash_aliases' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># sort file/directory sizes in current directory in human readable format </span><span style="color:#323232;">a s=</span><span style="color:#183691;">'du -sh -- * | sort -h' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># save last command from history to a file </span><span style="font-style:italic;color:#969896;"># tip, add a comment to end of command before saving, ex: ls --color=auto # colored ls output </span><span style="color:#323232;">a sl=</span><span style="color:#183691;">'fc -ln -1 | sed "s/^s*//" >> ~/.saved_commands.txt' </span><span style="font-style:italic;color:#969896;"># short-cut to grep that file </span><span style="color:#323232;">a slg=</span><span style="color:#183691;">'< ~/.saved_commands.txt grep' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># change ascii alphabets to unicode bold characters </span><span style="color:#323232;">a ascii2bold=</span><span style="color:#183691;">"perl -Mopen=locale -Mutf8 -pe 'tr/a-zA-Z/𝗮-𝘇𝗔-𝗭/'" </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;">### functions </span><span style="font-style:italic;color:#969896;"># 'command help' for command name and single option - ex: ch ls -A </span><span style="font-style:italic;color:#969896;"># see https://github.com/learnbyexample/command_help for a better script version </span><span style="font-weight:bold;color:#795da3;">ch</span><span style="color:#323232;">() { whatis $1</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">man $1 </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#323232;">sed -n </span><span style="color:#183691;">"/^s*$</span><span style="color:#323232;">2</span><span style="color:#183691;">/,/^$/p" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># add path to filename(s) </span><span style="font-style:italic;color:#969896;"># usage: ap file1 file2 etc </span><span style="font-weight:bold;color:#795da3;">ap</span><span style="color:#323232;">() { </span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> f </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#183691;">"$</span><span style="color:#323232;">@</span><span style="color:#183691;">"</span><span style="font-weight:bold;color:#a71d5d;">; do </span><span style="color:#62a35c;">echo </span><span style="color:#183691;">"$</span><span style="color:#323232;">PWD</span><span style="color:#183691;">/$</span><span style="color:#323232;">f</span><span style="color:#183691;">"</span><span style="font-weight:bold;color:#a71d5d;">; done; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># simple case-insensitive file search based on name </span><span style="font-style:italic;color:#969896;"># usage: fs name </span><span style="font-style:italic;color:#969896;"># remove '-type f' if you want to match directories as well </span><span style="font-weight:bold;color:#795da3;">fs</span><span style="color:#323232;">() { find -type f -iname </span><span style="color:#183691;">'*'"$</span><span style="color:#323232;">1</span><span style="color:#183691;">"'*' </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># open files with default application, don't print output/error messages </span><span style="font-style:italic;color:#969896;"># useful for opening docs, pdfs, images, etc from command line </span><span style="font-weight:bold;color:#795da3;">o</span><span style="color:#323232;">() { xdg-open </span><span style="color:#183691;">"$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">;></span><span style="color:#323232;"> /dev/null </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># if unix2dos and dos2unix commands aren't available by default </span><span style="font-weight:bold;color:#795da3;">unix2dos</span><span style="color:#323232;">() { sed -i </span><span style="color:#183691;">'s/$/r/' "$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="font-weight:bold;color:#795da3;">dos2unix</span><span style="color:#323232;">() { sed -i </span><span style="color:#183691;">'s/r$//' "$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span>
<span style="color:#62a35c;">alias </span><span style="font-weight:bold;color:#795da3;">a</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">'alias' </span><span style="color:#323232;"> </span><span style="color:#323232;">a c=</span><span style="color:#183691;">'clear' </span><span style="color:#323232;">a p=</span><span style="color:#183691;">'pwd' </span><span style="color:#323232;">a e=</span><span style="color:#183691;">'exit' </span><span style="color:#323232;">a q=</span><span style="color:#183691;">'exit' </span><span style="color:#323232;"> </span><span style="color:#323232;">a h=</span><span style="color:#183691;">'history | tail -n20' </span><span style="font-style:italic;color:#969896;"># turn off history, use 'set -o history' to turn it on again </span><span style="color:#323232;">a so=</span><span style="color:#183691;">'set +o history' </span><span style="color:#323232;"> </span><span style="color:#323232;">a b1=</span><span style="color:#183691;">'cd ../' </span><span style="color:#323232;">a b2=</span><span style="color:#183691;">'cd ../../' </span><span style="color:#323232;">a b3=</span><span style="color:#183691;">'cd ../../../' </span><span style="color:#323232;">a b4=</span><span style="color:#183691;">'cd ../../../../' </span><span style="color:#323232;">a b5=</span><span style="color:#183691;">'cd ../../../../../' </span><span style="color:#323232;"> </span><span style="color:#323232;">a ls=</span><span style="color:#183691;">'ls --color=auto' </span><span style="color:#323232;">a l=</span><span style="color:#183691;">'ls -ltrhG' </span><span style="color:#323232;">a la=</span><span style="color:#183691;">'l -A' </span><span style="color:#323232;">a vi=</span><span style="color:#183691;">'gvim' </span><span style="color:#323232;">a grep=</span><span style="color:#183691;">'grep --color=auto' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># open and source aliases </span><span style="color:#323232;">a oa=</span><span style="color:#183691;">'vi ~/.bash_aliases' </span><span style="color:#323232;">a sa=</span><span style="color:#183691;">'source ~/.bash_aliases' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># sort file/directory sizes in current directory in human readable format </span><span style="color:#323232;">a s=</span><span style="color:#183691;">'du -sh -- * | sort -h' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># save last command from history to a file </span><span style="font-style:italic;color:#969896;"># tip, add a comment to end of command before saving, ex: ls --color=auto # colored ls output </span><span style="color:#323232;">a sl=</span><span style="color:#183691;">'fc -ln -1 | sed "s/^s*//" >> ~/.saved_commands.txt' </span><span style="font-style:italic;color:#969896;"># short-cut to grep that file </span><span style="color:#323232;">a slg=</span><span style="color:#183691;">'< ~/.saved_commands.txt grep' </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># change ascii alphabets to unicode bold characters </span><span style="color:#323232;">a ascii2bold=</span><span style="color:#183691;">"perl -Mopen=locale -Mutf8 -pe 'tr/a-zA-Z/𝗮-𝘇𝗔-𝗭/'" </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;">### functions </span><span style="font-style:italic;color:#969896;"># 'command help' for command name and single option - ex: ch ls -A </span><span style="font-style:italic;color:#969896;"># see https://github.com/learnbyexample/command_help for a better script version </span><span style="font-weight:bold;color:#795da3;">ch</span><span style="color:#323232;">() { whatis $1</span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">man $1 </span><span style="font-weight:bold;color:#a71d5d;">| </span><span style="color:#323232;">sed -n </span><span style="color:#183691;">"/^s*$</span><span style="color:#323232;">2</span><span style="color:#183691;">/,/^$/p" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># add path to filename(s) </span><span style="font-style:italic;color:#969896;"># usage: ap file1 file2 etc </span><span style="font-weight:bold;color:#795da3;">ap</span><span style="color:#323232;">() { </span><span style="font-weight:bold;color:#a71d5d;">for</span><span style="color:#323232;"> f </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#183691;">"$</span><span style="color:#323232;">@</span><span style="color:#183691;">"</span><span style="font-weight:bold;color:#a71d5d;">; do </span><span style="color:#62a35c;">echo </span><span style="color:#183691;">"$</span><span style="color:#323232;">PWD</span><span style="color:#183691;">/$</span><span style="color:#323232;">f</span><span style="color:#183691;">"</span><span style="font-weight:bold;color:#a71d5d;">; done; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># simple case-insensitive file search based on name </span><span style="font-style:italic;color:#969896;"># usage: fs name </span><span style="font-style:italic;color:#969896;"># remove '-type f' if you want to match directories as well </span><span style="font-weight:bold;color:#795da3;">fs</span><span style="color:#323232;">() { find -type f -iname </span><span style="color:#183691;">'*'"$</span><span style="color:#323232;">1</span><span style="color:#183691;">"'*' </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># open files with default application, don't print output/error messages </span><span style="font-style:italic;color:#969896;"># useful for opening docs, pdfs, images, etc from command line </span><span style="font-weight:bold;color:#795da3;">o</span><span style="color:#323232;">() { xdg-open </span><span style="color:#183691;">"$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp</span><span style="font-weight:bold;color:#a71d5d;">;></span><span style="color:#323232;"> /dev/null </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="color:#323232;"> </span><span style="font-style:italic;color:#969896;"># if unix2dos and dos2unix commands aren't available by default </span><span style="font-weight:bold;color:#795da3;">unix2dos</span><span style="color:#323232;">() { sed -i </span><span style="color:#183691;">'s/$/r/' "$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span><span style="font-weight:bold;color:#795da3;">dos2unix</span><span style="color:#323232;">() { sed -i </span><span style="color:#183691;">'s/r$//' "$</span><span style="color:#323232;">@</span><span style="color:#183691;">" </span><span style="font-weight:bold;color:#a71d5d;">; </span><span style="color:#323232;">} </span>