Skip to content

Instantly share code, notes, and snippets.

@baradhiren
Created August 28, 2019 14:38
Show Gist options
  • Save baradhiren/c53338533618813dc5d9c6ff841e6cea to your computer and use it in GitHub Desktop.
Save baradhiren/c53338533618813dc5d9c6ff841e6cea to your computer and use it in GitHub Desktop.
Termux bashrc with common aliases and functions
#########
# Aliases
#########
# Always copy contents of directories (r)ecursively and explain (v) what was done
alias cp='cp -rv'
# List contents with colors for file types, (A)lmost all hidden files (without . and ..), in (C)olumns, with class indicators (F)
alias ls='ls --color=auto -ACF'
# List contents with colors for file types, (a)ll hidden entries (including . and ..), use (l)ong listing format, with class indicators >
alias ll='ls --color=auto -alF'
# Explain (v) what was done when moving a file
alias mv='mv -v'
# Create any non-existent (p)arent directories and explain (v) what was done
alias mkdir='mkdir -pv'
# Always try to (c)ontinue getting a partially-downloaded file
alias wget='wget -c'
# Use ll to list contents of a directory in detail
alias ll="ls -lhA"
# Find current directory for given name
alias fhere="find . -name "
# cd using ..
alias ..="cd .."
# Make all parent directories if not available
alias mkdir="mkdir -pv"
# Always continue downloads done by wget
alias wget="wget -c"
# Search history for command
alias histg="history | grep"
###########
# Functions
###########
# Convert any webm files in current directory to mp3 and remove the webm files once done
convertToMP3() {
echo "Going to ~/storage/shared/Youtube"
cd ~/storage/shared/Youtube/
echo "Finding if there are any webm files and converting them to MP3"
find . -type f -iname "*.webm" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";' _ '{}' \;
echo "Removing the webm files"
rm ./*.webm
}
export convertToMP3
# Create a directory and move into it
mcd () {
mkdir -p $1
cd $1
}
# Extract any compressed file
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
return 1
else
for n in $@
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment