feat: extract function helper
This commit is contained in:
parent
c59ba0e86b
commit
f714c19c58
4 changed files with 42 additions and 4 deletions
14
configs/shell/.zsh/functions/helpers.zsh
Normal file
14
configs/shell/.zsh/functions/helpers.zsh
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
params_required() {
|
||||||
|
local param_name="$1"
|
||||||
|
local param_value="$2"
|
||||||
|
local error_message="$3"
|
||||||
|
|
||||||
|
if [ -z "$error_message" ]; then
|
||||||
|
error_message="Parameter '$param_name' is required but not provided."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$param_value" ]; then
|
||||||
|
echo "$error_message" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
|
@ -7,3 +7,26 @@ convert_video_to_gif() {
|
||||||
|
|
||||||
echo "GIF created: $output_filename"
|
echo "GIF created: $output_filename"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extract() {
|
||||||
|
params_required "File" "$1" "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
*.tar.bz2) tar xvjf $1 ;;
|
||||||
|
*.tar.gz) tar xvzf $1 ;;
|
||||||
|
*.tar.xz) tar xvJf $1 ;;
|
||||||
|
*.lzma) unlzma $1 ;;
|
||||||
|
*.bz2) bunzip2 $1 ;;
|
||||||
|
*.rar) unrar x -ad $1 ;;
|
||||||
|
*.gz) gunzip $1 ;;
|
||||||
|
*.tar) tar xvf $1 ;;
|
||||||
|
*.tbz2) tar xvjf $1 ;;
|
||||||
|
*.tgz) tar xvzf $1 ;;
|
||||||
|
*.zip) unzip $1 ;;
|
||||||
|
*.Z) uncompress $1 ;;
|
||||||
|
*.7z) 7z x $1 ;;
|
||||||
|
*.xz) unxz $1 ;;
|
||||||
|
*.exe) cabextract $1 ;;
|
||||||
|
*) echo "extract: '$1' - unknown archive method" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,11 @@ ZSH_THEME="nebirhos"
|
||||||
# zsh-autosuggestions: https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md
|
# zsh-autosuggestions: https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md
|
||||||
plugins=(zsh-syntax-highlighting zsh-autosuggestions git themes jsontools)
|
plugins=(zsh-syntax-highlighting zsh-autosuggestions git themes jsontools)
|
||||||
|
|
||||||
|
source $ZSH/oh-my-zsh.sh
|
||||||
|
source ~/.zsh/functions/helpers.zsh
|
||||||
|
source ~/.zsh/functions/main.zsh
|
||||||
|
source ~/.zsh/aliases/main.zsh
|
||||||
|
|
||||||
if [[ "$OS" = void ]]; then
|
if [[ "$OS" = void ]]; then
|
||||||
source ~/.zsh/os/void.zsh
|
source ~/.zsh/os/void.zsh
|
||||||
elif [[ "$OS" = debian ]]; then
|
elif [[ "$OS" = debian ]]; then
|
||||||
|
@ -16,8 +21,4 @@ else
|
||||||
echo "Unsupported operating system: $OS"
|
echo "Unsupported operating system: $OS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source $ZSH/oh-my-zsh.sh
|
|
||||||
source ~/.zsh/functions/main.zsh
|
|
||||||
source ~/.zsh/aliases/main.zsh
|
|
||||||
|
|
||||||
eval "$(atuin init zsh)"
|
eval "$(atuin init zsh)"
|
||||||
|
|
Loading…
Add table
Reference in a new issue