Created
April 6, 2018 23:14
-
-
Save lfarroco/8c8ad634037d680682e9442324ee281c to your computer and use it in GitHub Desktop.
Functions added to my .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
#svim: searches for an expression in a git repo and edits each result in a tab | |
function svim() { | |
RES="$(git grep -l "$1" | wc -l)" | |
CONF_MSG="Do you wish to edit these ${RES} results? (y/n)" | |
read -p "${CONF_MSG}" choice; | |
case "$choice" in | |
y|Y ) vim -p `git grep -l "$1"`;; | |
n|N ) echo "exiting";; | |
* ) echo "exiting"; | |
esac | |
} | |
#gg: alias to display the line number in a result from git grep | |
alias :gg="git grep -En" | |
#https://gist.github.com/stevekm/af7f201fa6dab1baec4c#file-bashrc-L48 | |
function install(){ | |
sudo apt install -y $1; | |
} | |
#https://gist.github.com/stevekm/af7f201fa6dab1baec4c#file-bashrc-L70 | |
function extract () { | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xjvf $1 ;; | |
*.tar.gz) tar xzvf $1 ;; | |
*.bz2) bzip2 -d $1 ;; | |
*.rar) unrar2dir $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xf $1 ;; | |
*.tbz2) tar xjf $1 ;; | |
*.tgz) tar xzf $1 ;; | |
*.zip) unzip2dir $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*.ace) unace x $1 ;; | |
*) echo "'$1' cannot be extracted via extract()" ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
#https://gist.github.com/stevekm/af7f201fa6dab1baec4c#file-bashrc-L64 | |
commit() { | |
git add $1 && git commit -m $2 && git push origin $3 | |
} | |
#https://gist.github.com/dotgc/62c527153da61e7e89a9#file-functions-bash-L24 | |
function compress() { | |
if [[ -n "$1" ]]; then | |
FILE=$1 | |
case $FILE in | |
*.tar ) shift && tar cf $FILE $* ;; | |
*.tar.bz2 ) shift && tar cjf $FILE $* ;; | |
*.tar.gz ) shift && tar czf $FILE $* ;; | |
*.tgz ) shift && tar czf $FILE $* ;; | |
*.zip ) shift && zip $FILE $* ;; | |
*.rar ) shift && rar $FILE $* ;; | |
esac | |
else | |
echo "usage: compress <foo.tar.gz> ./foo ./bar" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment