diff --git a/functions/set_overwrite_alias b/functions/set_alias_with_backup similarity index 78% rename from functions/set_overwrite_alias rename to functions/set_alias_with_backup index eb14e9e..c98e622 100644 --- a/functions/set_overwrite_alias +++ b/functions/set_alias_with_backup @@ -1,9 +1,9 @@ #!/usr/bin/env bash -# set_overwrite_alias - A Bash function to alias a command while preserving the original. +# set_alias_with_backup - A Bash function to alias a command while preserving the original. # # Usage: -# set_overwrite_alias +# set_alias_with_backup # # Parameters: # new_command: The command to alias to (e.g., "bat"). @@ -17,8 +17,8 @@ # # Example: # To alias "bat" as "cat" and preserve the original "cat" as "cat_", run: -# set_overwrite_alias bat cat -set_overwrite_alias() { +# set_alias_with_backup bat cat +set_alias_with_backup() { local new_cmd="$1" local alias_name="$2" @@ -28,12 +28,12 @@ set_overwrite_alias() { fi # Check that the new command exists. - if type "$new_cmd" >/dev/null 2>&1; then + if type "$new_cmd" >/dev/null 2>&1;then # Define a backup alias by appending an underscore (e.g., "cat_" for "cat") local backup_alias="${alias_name}_" # If the backup alias isn't already set, create it pointing to the original command. - if ! command -v "$backup_alias" &>/dev/null; then + if ! type "$backup_alias" >/dev/null 2>&1; then alias "$backup_alias"="$(which "$alias_name")" fi diff --git a/home/config/aliases b/home/config/aliases index ed16d13..a0ce1ba 100644 --- a/home/config/aliases +++ b/home/config/aliases @@ -127,11 +127,11 @@ if type eza >/dev/null 2>&1; then alias lX='ll --sort=ext' fi -set_overwrite_alias bat cat -set_overwrite_alias doggo dig -set_overwrite_alias duf df -set_overwrite_alias gping ping -set_overwrite_alias dust du +set_alias_with_backup bat cat +set_alias_with_backup doggo dig +set_alias_with_backup duf df +set_alias_with_backup gping ping +set_alias_with_backup dust du ##### Mac OS Specific ##### if [ "$(uname)" = "Darwin" ]; then diff --git a/home/config/zsh/.zshrc b/home/config/zsh/.zshrc index 5cf74cb..c4bca3e 100644 --- a/home/config/zsh/.zshrc +++ b/home/config/zsh/.zshrc @@ -51,7 +51,7 @@ setopt no_beep # Don't beep on command input error # Include functions fpath+=~/Git/dotfiles/functions autoload extract -autoload set_overwrite_alias +autoload set_alias_with_backup [ -f $ZDOTDIR/.zshrc.local ] && source $ZDOTDIR/.zshrc.local [ -f ~/.config/.aliases ] && source ~/.config/.aliases