diff --git a/configs/host/bin/rofi-1.7.5.tar.gz b/configs/host/bin/rofi-1.7.5.tar.gz new file mode 100644 index 0000000..5c8727d Binary files /dev/null and b/configs/host/bin/rofi-1.7.5.tar.gz differ diff --git a/configs/shell/.zsh/functions/helpers.zsh b/configs/shell/.zsh/functions/helpers.zsh index 68b119b..ed581ee 100644 --- a/configs/shell/.zsh/functions/helpers.zsh +++ b/configs/shell/.zsh/functions/helpers.zsh @@ -1,7 +1,7 @@ params_required() { local param_name="$1" - local param_value="$2" - local error_message="$3" + local error_message="$2" + local param_value="$3" if [ -z "$error_message" ]; then error_message="Parameter '$param_name' is required but not provided." @@ -12,3 +12,21 @@ params_required() { exit 1 fi } + +validate_params() { + local error_message="$1" + shift + local required_params=("$@") + local missing_params=() + + for param in "${required_params[@]}"; do + if [ -z "${!param}" ]; then + missing_params+=("$param") + fi + done + + if [ ${#missing_params[@]} -gt 0 ]; then + echo "$error_message Missing parameters: ${missing_params[*]}" >&2 + exit 1 + fi +} diff --git a/configs/shell/.zsh/functions/main.zsh b/configs/shell/.zsh/functions/main.zsh index 2e68ddf..3b70a3a 100644 --- a/configs/shell/.zsh/functions/main.zsh +++ b/configs/shell/.zsh/functions/main.zsh @@ -1,3 +1,5 @@ +source ~/.zsh/functions/helpers.zsh + convert_video_to_gif() { local fps=60 local input_video="$1" @@ -9,7 +11,7 @@ convert_video_to_gif() { } extract() { - params_required "File" "$1" "Usage: extract ." + params_required "File" "Usage: extract [path/compressed_filename]" "$1" case $1 in *.tar.bz2) tar xvjf $1 ;; @@ -29,4 +31,32 @@ extract() { *.exe) cabextract $1 ;; *) echo "extract: '$1' - unknown archive method" ;; esac + + if [ $? -eq 0 ]; then + echo "File extracted successfully: $1" + else + echo "Failed to extract file: $1" + fi +} + +compress() { + params_required "File" "Usage: compress [compressed_filename]. " "$1" + + compressed_filename="$1" + file_or_dir="$2" + + case $compressed_filename in + *.tar) tar cvf "$compressed_filename" "$file_or_dir" ;; + *.tar.gz) tar czvf "$compressed_filename" "$file_or_dir" ;; + *.tar.bz2) tar cjvf "$compressed_filename" "$file_or_dir" ;; + *.tar.xz) tar cJvf "$compressed_filename" "$file_or_dir" ;; + *.zip) zip -r "$compressed_filename" "$file_or_dir" ;; + *) echo "compress: '$compressed_filename' - unknown compression method" ;; + esac + + if [ $? -eq 0 ]; then + echo "Compression successful: $compressed_filename" + else + echo "Compression failed: $compressed_filename" + fi } diff --git a/configs/shell/.zshrc b/configs/shell/.zshrc index 9d971a9..e4e5c41 100644 --- a/configs/shell/.zshrc +++ b/configs/shell/.zshrc @@ -9,7 +9,6 @@ ZSH_THEME="nebirhos" 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 diff --git a/scripts/utils/main.sh b/scripts/utils/main.sh index e9846f0..d690717 100755 --- a/scripts/utils/main.sh +++ b/scripts/utils/main.sh @@ -24,9 +24,14 @@ check() { 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 - log "Parameter '$param_name' is required but not provided." + echo "$error_message" >&2 exit 1 fi }