mirror of
https://github.com/sebaschi/dotfiles.git
synced 2025-12-29 18:18:28 +01:00
New aliases
This commit is contained in:
51
bash/bash_functions
Normal file
51
bash/bash_functions
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
### ARCHIVE EXTRACTION
|
||||
# usage: ex <file>
|
||||
function ex {
|
||||
if [ -z "$1" ]; then
|
||||
# display usage if no parameters given
|
||||
echo "Usage: ex <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]"
|
||||
else
|
||||
for n in "$@"
|
||||
do
|
||||
if [ -f "$n" ] ; then
|
||||
case "${n%,}" in
|
||||
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
|
||||
tar xvf "$n" ;;
|
||||
*.lzma) unlzma ./"$n" ;;
|
||||
*.bz2) bunzip2 ./"$n" ;;
|
||||
*.cbr|*.rar) unrar x -ad ./"$n" ;;
|
||||
*.gz) gunzip ./"$n" ;;
|
||||
*.cbz|*.epub|*.zip) unzip ./"$n" ;;
|
||||
*.z) uncompress ./"$n" ;;
|
||||
*.7z|*.arj|*.cab|*.cb7|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar)
|
||||
7z x ./"$n" ;;
|
||||
*.xz) unxz ./"$n" ;;
|
||||
*.exe) cabextract ./"$n" ;;
|
||||
*.cpio) cpio -id < ./"$n" ;;
|
||||
*.cba|*.ace) unace x ./"$n" ;;
|
||||
*)
|
||||
echo "ex: '$n' - unknown archive method"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "'$n' - file does not exist"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function ensure {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: ensure <command>"
|
||||
else
|
||||
if ! command -v $1 &> /dev/null
|
||||
then
|
||||
echo "$1 could not be found"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user