diff --git a/dot_config/zsh/dot_zsh_plugins.txt b/dot_config/zsh/dot_zsh_plugins.txt index 9bc706e..a707551 100644 --- a/dot_config/zsh/dot_zsh_plugins.txt +++ b/dot_config/zsh/dot_zsh_plugins.txt @@ -30,9 +30,6 @@ MichaelAquilina/zsh-you-should-use asdf-vm/asdf olets/zsh-abbr -# theme -#romkatv/powerlevel10k - # fish like zsh-users/zsh-autosuggestions zsh-users/zsh-syntax-highlighting diff --git a/dot_config/zsh/dot_zshrc b/dot_config/zsh/dot_zshrc index 8e3ff0d..823154c 100644 --- a/dot_config/zsh/dot_zshrc +++ b/dot_config/zsh/dot_zshrc @@ -7,12 +7,13 @@ eval "$potentialBanner[$RANDOM%$#potentialBanner+1]" function source () { test -r "$1" && builtin source "$1" } +stty -ixon + # local env exports source "$XDG_DATA_HOME"/zsh/config/env.zsh # completion stuff source "$ZDOTDIR"/files/compinit.zsh -source "$ZDOTDIR"/files/bashcomps.zsh source "$ZDOTDIR"/files/sshcomp.zsh # antidote @@ -26,3 +27,11 @@ source "$ZDOTDIR"/files/evalstuff.zsh source "$ZDOTDIR"/files/aliases.zsh source "$ZDOTDIR"/files/functions.zsh source "$ZDOTDIR"/files/distroicon.zsh + +# bash completions +source "$ZDOTDIR"/files/bashcomps.zsh + +# theme +potentialTheme=('atomic.omp.json' 'emodipt-extend.omp.json' 'kali.omp.json' 'lambda.omp.json' 'nordtron.omp.json' 'pure.omp.json' 'uew.omp.json') +export POSH_THEME="$XDG_DATA_HOME/omp/themes/$potentialTheme[$RANDOM%$#potentialTheme+1]" +eval "$(oh-my-posh init zsh)" \ No newline at end of file diff --git a/dot_config/zsh/files/evalstuff.zsh b/dot_config/zsh/files/evalstuff.zsh index 1eeba07..5102e34 100644 --- a/dot_config/zsh/files/evalstuff.zsh +++ b/dot_config/zsh/files/evalstuff.zsh @@ -1,17 +1,3 @@ -# starship -#_evalcache starship init zsh --print-full-init - -# ohmyposh -potentialTheme=('atomic.omp.json' 'emodipt-extend.omp.json' 'kali.omp.json' 'lambda.omp.json' 'nordtron.omp.json' 'pure.omp.json' 'uew.omp.json') -if (( ${+commands[brew]} )); then - export POSH_THEME="$(brew --prefix oh-my-posh)/themes/$potentialTheme[$RANDOM%$#potentialTheme+1]" -elif test "$(cat /etc/os-release | grep '^ID=' | cut -d'=' -f2)" = "nixos"; then - export POSH_THEME="/run/current-system/sw/share/oh-my-posh/themes/$potentialTheme[$RANDOM%$#potentialTheme+1]" -else - export POSH_THEME="/usr/share/oh-my-posh/themes/$potentialTheme[$RANDOM%$#potentialTheme+1]" -fi -eval "$(oh-my-posh init zsh)" - # evalstuff _evalcache zoxide init --cmd cd zsh _evalcache atuin init zsh diff --git a/dot_config/zsh/files/mal.zsh b/dot_config/zsh/files/mal.zsh new file mode 100644 index 0000000..fc14d7d --- /dev/null +++ b/dot_config/zsh/files/mal.zsh @@ -0,0 +1,195 @@ +export ALIASES_FILE="$XDG_CONFIG_HOME"/aliasesrc + +function mal { + # Use fzf to allow the user to select an alias from the aliases file + function _execute_alias { + local alias_to_execute=$(cut -d' ' -f2- "$ALIASES_FILE" | fzf) + + # Check if the user cancelled the selection + test -z $alias_to_execute && return 1 + + echo "Executing alias: $alias_to_execute" + # Execute the selected alias + eval ${alias_to_execute%%=*} + return 0 + } + + # Delete an existing alias by selecting it from a list + function _interactive_delete { + local alias_to_delete=$(cut -d' ' -f2- "$ALIASES_FILE" | fzf) + + # Check if the user cancelled the selection + test -z $alias_to_delete && return 1 + + echo "Deleted alias: $alias_to_delete" + # Delete the selected alias from the aliases file + sed -i "/^alias ${alias_to_delete%%=*}=/d" "$ALIASES_FILE" + unalias ${alias_to_delete%%=*} + } + + # Delete an existing alias using specified name + function _parameter_delete { + local alias_to_delete=$1 + local line_with_alias=$(grep "$1=" "$ALIASES_FILE") + + # Check if the alias exists in the aliases file + if test -z "$line_with_alias"; then + echo "No alias with the name $1 found." + return 2 + fi + + echo "Deleted alias: $alias_to_delete" + # Delete the selected alias from the aliases file + sed -i "/^alias ${alias_to_delete%%=*}=/d" "$ALIASES_FILE" + unalias ${alias_to_delete%%=*} + } + + # Rename an existing alias by selecting it from a list + function _interactive_rename { + local alias_to_rename=$(cut -d' ' -f2- "$ALIASES_FILE" | fzf) + + # Check if the user cancelled the selection + test -z $alias_to_rename && return 1 + + echo "Input new name:" + read new_name + echo "Renaming alias from $alias_to_rename to $new_name" + sed -i "s/^alias ${alias_to_rename%%=*}=/alias ${new_name}=/g" "$ALIASES_FILE" + unalias ${alias_to_rename%%=*} + } + + # Rename an existing alias using specified old and new names + function _parameter_rename { + local old_alias_name=$1 + local new_alias_name=$2 + local line_with_alias=$(grep "^alias ${old_alias_name}=" "$ALIASES_FILE") + + if test -z "$line_with_alias"; then + echo "No alias with the name $old_alias_name found." + return 1 + fi + + echo "Renaming alias from $old_alias_name to $new_alias_name" + sed -i "s/^alias ${old_alias_name}=/alias ${new_alias_name}=/g" "$ALIASES_FILE" + unalias ${old_alias_name} + } + + # Change the command associated with an existing alias by selecting it from a list + function _interactive_command_change { + local alias_to_change=$(cut -d' ' -f2- "$ALIASES_FILE" | fzf) + + # Check if the user cancelled the selection + test -z $alias_to_change && return 1 + + echo "Input new command:" + read new_command + echo "Changing command for alias ${alias_to_change%%=*} to \"$new_command\"" + sed -i "/^alias ${alias_to_change%%=*}=/{s/=.*/=\"$new_command\"/}" "$ALIASES_FILE" + } + + # Change the command associated with an existing alias using specified name and command + function _parameter_command_change { + local alias_to_change=$1 + local new_command="${@:2}" + local line_with_alias=$(grep "$alias_to_change=" "$ALIASES_FILE") + + if test -z "$line_with_alias"; then + echo "No alias with the name $alias_to_change found." + return 1 + fi + + echo "Changing command for alias $alias_to_change to \"$new_command\"" + sed -i "/^alias ${alias_to_change}=/{s/=.*/=\"$new_command\"/}" "$ALIASES_FILE" + } + + # Add a new alias + function _add_command { + local line_with_alias=$(grep "$1=" "$ALIASES_FILE") + + if test ! -z "$line_with_alias"; then + echo "Alias found: $line_with_alias; change alias by using the -c flag." + return 1 + fi + + local lh="alias $1" + local rh=\"${@:2}\" + local alias_str="$lh=$rh" + + echo $alias_str >>"$ALIASES_FILE" + echo "added '$alias_str' to .aliases" + } + + # List all aliases from the aliases file + function _list_aliases { + cut -d' ' -f2- "$ALIASES_FILE" | command cat + } + + # ============================================================================================================================================================== + + action="$1" + param1="$2" + param2="$3" + + # Check if the user has provided a help option or no arguments + helpParams=('-h' '--help' '-help') + if (($helpParams[(Ie)$action])) || test $# -eq 0; then + # Display usage information + echo "Usage: mal [OPTION]... [ALIAS_NAME] [ALIAS_COMMAND]..." + echo "" + echo "Create, delete, change, or execute aliases interactively." + echo "" + echo "Options:" + echo " -h, --help display this help and exit" + echo " -l list all defined aliases" + echo " -e execute an alias interactively" + echo " -d delete an alias interactively" + echo " -dn NAME delete an alias by name" + echo " -r rename an alias interactively" + echo " -rn OLD NEW rename an existing alias" + echo " -c change the command associated with an existing alias interactively" + echo " -cc NAME COMMAND change the command associated with an existing alias by name" + return 0 + fi + + case "$action" in + "-e") + # Execute an alias interactively + _execute_alias + ;; + "-l") + # List all aliases + _list_aliases + ;; + "-d") + # Delete an alias interactively + _interactive_delete + ;; + "-dn") + # Delete an alias using a parameter + _parameter_delete "$param1" + ;; + "-r") + # rename an alias interactively + _interactive_rename + ;; + "-rn") + # rename an alias using parameters + _parameter_rename "$param1" "$param2" + ;; + "-c") + # change a command interactively + _interactive_command_change + ;; + "-cc") + # change a command using parameters + _parameter_command_change "$param1" "$param2" + ;; + *) + # add a new command + _add_command "$action" "$param1" + ;; + esac + + # Reload aliases + source "$ALIASES_FILE" +}