feat: rofi app

This commit is contained in:
hesam-init 2024-03-24 11:44:53 +03:30
parent 0e38fd06a7
commit ec52b373d2
5 changed files with 57 additions and 5 deletions

Binary file not shown.

View file

@ -1,7 +1,7 @@
params_required() { params_required() {
local param_name="$1" local param_name="$1"
local param_value="$2" local error_message="$2"
local error_message="$3" local param_value="$3"
if [ -z "$error_message" ]; then if [ -z "$error_message" ]; then
error_message="Parameter '$param_name' is required but not provided." error_message="Parameter '$param_name' is required but not provided."
@ -12,3 +12,21 @@ params_required() {
exit 1 exit 1
fi 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
}

View file

@ -1,3 +1,5 @@
source ~/.zsh/functions/helpers.zsh
convert_video_to_gif() { convert_video_to_gif() {
local fps=60 local fps=60
local input_video="$1" local input_video="$1"
@ -9,7 +11,7 @@ convert_video_to_gif() {
} }
extract() { 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>" params_required "File" "Usage: extract [path/compressed_filename]" "$1"
case $1 in case $1 in
*.tar.bz2) tar xvjf $1 ;; *.tar.bz2) tar xvjf $1 ;;
@ -29,4 +31,32 @@ extract() {
*.exe) cabextract $1 ;; *.exe) cabextract $1 ;;
*) echo "extract: '$1' - unknown archive method" ;; *) echo "extract: '$1' - unknown archive method" ;;
esac 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].<tar|tar.gz|zip> <file_or_directory>" "$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
} }

View file

@ -9,7 +9,6 @@ ZSH_THEME="nebirhos"
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/oh-my-zsh.sh
source ~/.zsh/functions/helpers.zsh
source ~/.zsh/functions/main.zsh source ~/.zsh/functions/main.zsh
source ~/.zsh/aliases/main.zsh source ~/.zsh/aliases/main.zsh

View file

@ -24,9 +24,14 @@ check() {
params_required() { params_required() {
local param_name="$1" local param_name="$1"
local param_value="$2" 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 if [ -z "$param_value" ]; then
log "Parameter '$param_name' is required but not provided." echo "$error_message" >&2
exit 1 exit 1
fi fi
} }