From b80c86d50fe386d4f08625d83e6c5027c33d9dbf Mon Sep 17 00:00:00 2001 From: Oblivionis <182329535+0blivi0nis@users.noreply.github.com> Date: Wed, 25 Sep 2024 19:17:41 -0700 Subject: [PATCH 1/8] Removed starship, zsh-completion, trizen, pacseek, added rsync because of dotfiles dependency and updated oh-my-posh to oh-my-posh-bin in general.sh. Updated grimblast to grimblast-git in hyprland.sh. Added trizen and pacseek to optional.sh. --- share/packages/general.sh | 7 ++----- share/packages/hyprland.sh | 2 +- share/packages/optional.sh | 2 ++ 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/share/packages/general.sh b/share/packages/general.sh index b0257fc2..42981dd1 100644 --- a/share/packages/general.sh +++ b/share/packages/general.sh @@ -9,7 +9,6 @@ packagesPacman=( "unzip" "alacritty" "dunst" - "starship" "noto-fonts" "otf-font-awesome" "ttf-fira-sans" @@ -53,12 +52,10 @@ packagesPacman=( "zsh" "fzf" "htop" - "zsh-completions" + "rsync" ); packagesAUR=( "bibata-cursor-theme" - "trizen" - "pacseek" - "oh-my-posh" + "oh-my-posh-bin" ); diff --git a/share/packages/hyprland.sh b/share/packages/hyprland.sh index a3470b5a..707921f0 100644 --- a/share/packages/hyprland.sh +++ b/share/packages/hyprland.sh @@ -15,7 +15,7 @@ packagesAUR=( "wlogout" "hyprshade" "waypaper" - "grimblast" + "grimblast-git" "bun-bin" "aylurs-gtk-shell" ); diff --git a/share/packages/optional.sh b/share/packages/optional.sh index f5457c35..4e0235a7 100755 --- a/share/packages/optional.sh +++ b/share/packages/optional.sh @@ -1,4 +1,6 @@ optdepends=( + "trizen" + "pacseek" "firefox" "flatpak" "gnome-calculator" From 0f0c1c33c246361eb03422d9ee171ef57123eefd Mon Sep 17 00:00:00 2001 From: Oblivionis <182329535+0blivi0nis@users.noreply.github.com> Date: Wed, 25 Sep 2024 19:23:52 -0700 Subject: [PATCH 2/8] Zen ZSH: Removed starship completely to use oh-my-posh. Updated both bash and zsh to use posh and addded a variable for built in oh-my-posh themes. Removed oh-my-zsh since it slows down boot times and is not really needed. Added some basic plugins in the plugin folder. The post install shell script still installs all the previous plugins used by oh-my-zsh and also install zsh-completions but sources it manually removing the need for oh-my-zsh completely. --- lib/install/dotfiles/before_restore.sh | 2 - .../dotfiles/.config/bashrc/20-customization | 14 +- share/dotfiles/.config/bashrc/30-autostart | 6 + share/dotfiles/.config/ml4w/scripts/shell.sh | 33 ++- share/dotfiles/.config/zshrc/20-customization | 41 +-- .../plugins/colored-man-pages.plugin.zsh | 54 ++++ .../plugins/command-not-found.plugin.zsh | 70 +++++ .../zshrc/plugins/dirhistory.plugin.zsh | 225 ++++++++++++++ .../.config/zshrc/plugins/extract.plugin.zsh | 137 +++++++++ .../.config/zshrc/plugins/sudo.plugin.zsh | 108 +++++++ .../zshrc/plugins/you-should-use.plugin.zsh | 279 ++++++++++++++++++ 11 files changed, 922 insertions(+), 47 deletions(-) create mode 100644 share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh create mode 100644 share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh create mode 100644 share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh create mode 100644 share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh create mode 100644 share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh create mode 100644 share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh diff --git a/lib/install/dotfiles/before_restore.sh b/lib/install/dotfiles/before_restore.sh index a2c1661a..fbbacfea 100755 --- a/lib/install/dotfiles/before_restore.sh +++ b/lib/install/dotfiles/before_restore.sh @@ -32,10 +32,8 @@ if [ -d ~/$dot_folder/.settings ] ;then _move_folder ~/$dot_folder/.config/gtk/xsettings ~/$dot_folder/.config/xsettings _move_file ~/$dot_folder/.config/gtk/.gtkrc-2.0 ~/$dot_folder/.gtkrc-2.0 _move_file ~/$dot_folder/.config/gtk/.Xresources ~/$dot_folder/.Xresources - _move_file ~/$dot_folder/.config/starship/starship.toml ~/$dot_folder/.config/starship.toml _del_folder ~/$dot_folder/gtk _del_folder ~/$dot_folder/eww - _del_folder ~/$dot_folder/starship # Replace Quicklink sed -i -e 's/dotfiles\/.settings/.config\/ml4w\/settings/g' ~/$dot_folder/.config/ml4w/settings/waybar-quicklinks.json diff --git a/share/dotfiles/.config/bashrc/20-customization b/share/dotfiles/.config/bashrc/20-customization index ad9d9a5e..34925593 100644 --- a/share/dotfiles/.config/bashrc/20-customization +++ b/share/dotfiles/.config/bashrc/20-customization @@ -2,12 +2,14 @@ # CUSTOMIZATION # ----------------------------------------------------- -# ----------------------------------------------------- -# Starship Prompt -# ----------------------------------------------------- -eval "$(starship init bash)" +POSH=agnoster # ----------------------------------------------------- -# Pywal +# oh-my-posh promt # ----------------------------------------------------- -cat ~/.cache/wal/sequences +# Custom Theme +eval "$(oh-my-posh init zsh --config $HOME/.config/ohmyposh/zen.toml)" + +# Shipped Theme +# eval "$(oh-my-posh init zsh --config /usr/share/oh-my-posh/themes/$POSH.omp.json)" + diff --git a/share/dotfiles/.config/bashrc/30-autostart b/share/dotfiles/.config/bashrc/30-autostart index cf5909d5..497f302a 100644 --- a/share/dotfiles/.config/bashrc/30-autostart +++ b/share/dotfiles/.config/bashrc/30-autostart @@ -2,6 +2,12 @@ # AUTOSTART # ----------------------------------------------------- +# ----------------------------------------------------- +# Pywal +# ----------------------------------------------------- +cat ~/.cache/wal/sequences + + # ----------------------------------------------------- # Fastfetch # ----------------------------------------------------- diff --git a/share/dotfiles/.config/ml4w/scripts/shell.sh b/share/dotfiles/.config/ml4w/scripts/shell.sh index a40589c8..f3c743a0 100755 --- a/share/dotfiles/.config/ml4w/scripts/shell.sh +++ b/share/dotfiles/.config/ml4w/scripts/shell.sh @@ -51,19 +51,10 @@ elif [[ $shell == "zsh" ]] ;then done echo ":: Shell is now zsh." - # Installing oh-my-zsh - if [ ! -d "$HOME/.oh-my-zsh" ]; then - echo ":: Installing oh-my-zsh" - sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended - cp ~/.config/ml4w/tpl/.zshrc ~/ - else - echo ":: oh-my-zsh already installed" - fi - # Installing zsh-autosuggestions if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then echo ":: Installing zsh-autosuggestions" - git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions + git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.config/zshrc/plugins/zsh-autosuggestions else echo ":: zsh-autosuggestions already installed" fi @@ -71,7 +62,7 @@ elif [[ $shell == "zsh" ]] ;then # Installing zsh-syntax-highlighting if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]; then echo ":: Installing zsh-syntax-highlighting" - git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.config/zshrc/plugins/zsh-syntax-highlighting else echo ":: zsh-syntax-highlighting already installed" fi @@ -79,11 +70,29 @@ elif [[ $shell == "zsh" ]] ;then # Installing fast-syntax-highlighting if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/fast-syntax-highlighting" ]; then echo ":: Installing fast-syntax-highlighting" - git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting + git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git $HOME/.config/zshrc/plugins/fast-syntax-highlighting else echo ":: fast-syntax-highlighting already installed" fi + # Installing zsh-completions + if [ ! -d "$HOME/.config/zshrc/plugins/zsh-completions" ]; then + echo ":: Installing zsh-completions" + git clone https://github.com/zsh-users/zsh-completions.git $HOME/.config/zshrc/plugins/zsh-completions + else + echo ":: zsh-completions already installed" + fi + + # Install pkgfile if needed (for command not found) + if ! command -v pkgfile &> /dev/null; then + echo ":: Installing pkgfile" + sudo pacman -S pkgfile + else + echo ":: pkgfile already installed" + fi + + sudo pkgfile -u + gum spin --spinner dot --title "Please reboot your system." -- sleep 3 # ----------------------------------------------------- diff --git a/share/dotfiles/.config/zshrc/20-customization b/share/dotfiles/.config/zshrc/20-customization index 6c282999..0eddd3a9 100644 --- a/share/dotfiles/.config/zshrc/20-customization +++ b/share/dotfiles/.config/zshrc/20-customization @@ -2,29 +2,21 @@ # CUSTOMIZATION # ----------------------------------------------------- -# ----------------------------------------------------- -# oh-myzsh themes: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes -# ----------------------------------------------------- -# ZSH_THEME=robbyrussell +POSH=agnoster # ----------------------------------------------------- -# oh-myzsh plugins -# ----------------------------------------------------- -plugins=( - git - sudo - web-search - archlinux - zsh-autosuggestions - zsh-syntax-highlighting - fast-syntax-highlighting - copyfile - copybuffer - dirhistory -) - -# Set-up oh-my-zsh -source $ZSH/oh-my-zsh.sh +# PLUGINS +# ----------------------------------------------------- +source $HOME/.config/zshrc/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh +source $HOME/.config/zshrc/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh +source $HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh +source $HOME/.config/zshrc/plugins/zsh-completions/zsh-completions.plugin.zsh +source $HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh +source $HOME/.config/zshrc/plugins/command-not-found.plugin.zsh +source $HOME/.config/zshrc/plugins/dirhistory.plugin.zsh +source $HOME/.config/zshrc/plugins/extract.plugin.zsh +source $HOME/.config/zshrc/plugins/sudo.plugin.zsh +source $HOME/.config/zshrc/plugins/you-should-use.plugin.zsh # ----------------------------------------------------- # Set-up FZF key bindings (CTRL R for fuzzy history finder) @@ -37,11 +29,6 @@ HISTSIZE=10000 SAVEHIST=10000 setopt appendhistory -# ----------------------------------------------------- -# Starship promt -# ----------------------------------------------------- -# eval "$(starship init zsh)" - # ----------------------------------------------------- # oh-my-posh promt # ----------------------------------------------------- @@ -49,4 +36,4 @@ setopt appendhistory eval "$(oh-my-posh init zsh --config $HOME/.config/ohmyposh/zen.toml)" # Shipped Theme -# eval "$(oh-my-posh init zsh --config /usr/share/oh-my-posh/themes/agnoster.omp.json)" +# eval "$(oh-my-posh init zsh --config /usr/share/oh-my-posh/themes/$POSH.omp.json)" diff --git a/share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh new file mode 100644 index 00000000..57facbb5 --- /dev/null +++ b/share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh @@ -0,0 +1,54 @@ +# Requires colors autoload. +# See termcap(5). + +# Set up once, and then reuse. This way it supports user overrides after the +# plugin is loaded. +typeset -AHg less_termcap + +# bold & blinking mode +less_termcap[mb]="${fg_bold[red]}" +less_termcap[md]="${fg_bold[red]}" +less_termcap[me]="${reset_color}" +# standout mode +less_termcap[so]="${fg_bold[yellow]}${bg[blue]}" +less_termcap[se]="${reset_color}" +# underlining +less_termcap[us]="${fg_bold[green]}" +less_termcap[ue]="${reset_color}" + +# Handle $0 according to the standard: +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" + +# Absolute path to this file's directory. +typeset -g __colored_man_pages_dir="${0:A:h}" + +function colored() { + local -a environment + + # Convert associative array to plain array of NAME=VALUE items. + local k v + for k v in "${(@kv)less_termcap}"; do + environment+=( "LESS_TERMCAP_${k}=${v}" ) + done + + # Prefer `less` whenever available, since we specifically configured + # environment for it. + environment+=( PAGER="${commands[less]:-$PAGER}" ) + environment+=( GROFF_NO_SGR=1 ) + + # See ./nroff script. + if [[ "$OSTYPE" = solaris* ]]; then + environment+=( PATH="${__colored_man_pages_dir}:$PATH" ) + fi + + command env $environment "$@" +} + +# Colorize man and dman/debman (from debian-goodies) +function man \ + dman \ + debman { + colored $0 "$@" +} diff --git a/share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh new file mode 100644 index 00000000..0034b0ad --- /dev/null +++ b/share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh @@ -0,0 +1,70 @@ +## Platforms with a built-in command-not-found handler init file + +for file ( + # Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found + /usr/share/doc/pkgfile/command-not-found.zsh + # Homebrew: https://github.com/Homebrew/homebrew-command-not-found + /opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh + /usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh + /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh +); do + if [[ -r "$file" ]]; then + source "$file" + unset file + return 0 + fi +done +unset file + + +## Platforms with manual command_not_found_handler() setup + +# Debian and derivatives: https://launchpad.net/ubuntu/+source/command-not-found +if [[ -x /usr/lib/command-not-found || -x /usr/share/command-not-found/command-not-found ]]; then + command_not_found_handler() { + if [[ -x /usr/lib/command-not-found ]]; then + /usr/lib/command-not-found -- "$1" + return $? + elif [[ -x /usr/share/command-not-found/command-not-found ]]; then + /usr/share/command-not-found/command-not-found -- "$1" + return $? + else + printf "zsh: command not found: %s\n" "$1" >&2 + return 127 + fi + } +fi + +# Fedora: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound +if [[ -x /usr/libexec/pk-command-not-found ]]; then + command_not_found_handler() { + if [[ -S /var/run/dbus/system_bus_socket && -x /usr/libexec/packagekitd ]]; then + /usr/libexec/pk-command-not-found "$@" + return $? + fi + + printf "zsh: command not found: %s\n" "$1" >&2 + return 127 + } +fi + +# NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found +if [[ -x /run/current-system/sw/bin/command-not-found ]]; then + command_not_found_handler() { + /run/current-system/sw/bin/command-not-found "$@" + } +fi + +# Termux: https://github.com/termux/command-not-found +if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then + command_not_found_handler() { + /data/data/com.termux/files/usr/libexec/termux/command-not-found "$1" + } +fi + +# SUSE and derivates: https://www.unix.com/man-page/suse/1/command-not-found/ +if [[ -x /usr/bin/command-not-found ]]; then + command_not_found_handler() { + /usr/bin/command-not-found "$1" + } +fi \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh new file mode 100644 index 00000000..d90b7f8e --- /dev/null +++ b/share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh @@ -0,0 +1,225 @@ +## +# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories +# that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. +# +# Navigate directory hierarchy using ALT-UP and ALT-DOWN. +# ALT-UP moves to higher hierarchy (cd ..) +# ALT-DOWN moves into the first directory found in alphabetical order +# + +dirhistory_past=($PWD) +dirhistory_future=() +export dirhistory_past +export dirhistory_future + +export DIRHISTORY_SIZE=30 + +# Pop the last element of dirhistory_past. +# Pass the name of the variable to return the result in. +# Returns the element if the array was not empty, +# otherwise returns empty string. +function pop_past() { + setopt localoptions no_ksh_arrays + if [[ $#dirhistory_past -gt 0 ]]; then + typeset -g $1="${dirhistory_past[$#dirhistory_past]}" + dirhistory_past[$#dirhistory_past]=() + fi +} + +function pop_future() { + setopt localoptions no_ksh_arrays + if [[ $#dirhistory_future -gt 0 ]]; then + typeset -g $1="${dirhistory_future[$#dirhistory_future]}" + dirhistory_future[$#dirhistory_future]=() + fi +} + +# Push a new element onto the end of dirhistory_past. If the size of the array +# is >= DIRHISTORY_SIZE, the array is shifted +function push_past() { + setopt localoptions no_ksh_arrays + if [[ $#dirhistory_past -ge $DIRHISTORY_SIZE ]]; then + shift dirhistory_past + fi + if [[ $#dirhistory_past -eq 0 || $dirhistory_past[$#dirhistory_past] != "$1" ]]; then + dirhistory_past+=($1) + fi +} + +function push_future() { + setopt localoptions no_ksh_arrays + if [[ $#dirhistory_future -ge $DIRHISTORY_SIZE ]]; then + shift dirhistory_future + fi + if [[ $#dirhistory_future -eq 0 || $dirhistory_futuret[$#dirhistory_future] != "$1" ]]; then + dirhistory_future+=($1) + fi +} + +# Called by zsh when directory changes +autoload -U add-zsh-hook +add-zsh-hook chpwd chpwd_dirhistory +function chpwd_dirhistory() { + push_past $PWD + # If DIRHISTORY_CD is not set... + if [[ -z "${DIRHISTORY_CD+x}" ]]; then + # ... clear future. + dirhistory_future=() + fi +} + +function dirhistory_cd(){ + DIRHISTORY_CD="1" + cd $1 + unset DIRHISTORY_CD +} + +# Move backward in directory history +function dirhistory_back() { + local cw="" + local d="" + # Last element in dirhistory_past is the cwd. + + pop_past cw + if [[ "" == "$cw" ]]; then + # Someone overwrote our variable. Recover it. + dirhistory_past=($PWD) + return + fi + + pop_past d + if [[ "" != "$d" ]]; then + dirhistory_cd $d + push_future $cw + else + push_past $cw + fi +} + + +# Move forward in directory history +function dirhistory_forward() { + local d="" + + pop_future d + if [[ "" != "$d" ]]; then + dirhistory_cd $d + push_past $d + fi +} + + +# Bind keys to history navigation +function dirhistory_zle_dirhistory_back() { + # Erase current line in buffer + zle .kill-buffer + dirhistory_back + zle .accept-line +} + +function dirhistory_zle_dirhistory_future() { + # Erase current line in buffer + zle .kill-buffer + dirhistory_forward + zle .accept-line +} + +zle -N dirhistory_zle_dirhistory_back +zle -N dirhistory_zle_dirhistory_future + +for keymap in emacs vicmd viins; do + # dirhistory_back + bindkey -M $keymap "\e[3D" dirhistory_zle_dirhistory_back # xterm in normal mode + bindkey -M $keymap "\e[1;3D" dirhistory_zle_dirhistory_back # xterm in normal mode + bindkey -M $keymap "\e\e[D" dirhistory_zle_dirhistory_back # Putty + bindkey -M $keymap "\eO3D" dirhistory_zle_dirhistory_back # GNU screen + + case "$TERM_PROGRAM" in + Apple_Terminal) bindkey -M $keymap "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app + iTerm.app) bindkey -M $keymap "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2 + esac + + if (( ${+terminfo[kcub1]} )); then + bindkey -M $keymap "^[${terminfo[kcub1]}" dirhistory_zle_dirhistory_back # urxvt + fi + + # dirhistory_future + bindkey -M $keymap "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode + bindkey -M $keymap "\e[1;3C" dirhistory_zle_dirhistory_future # xterm in normal mode + bindkey -M $keymap "\e\e[C" dirhistory_zle_dirhistory_future # Putty + bindkey -M $keymap "\eO3C" dirhistory_zle_dirhistory_future # GNU screen + + case "$TERM_PROGRAM" in + Apple_Terminal) bindkey -M $keymap "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app + iTerm.app) bindkey -M $keymap "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2 + esac + + if (( ${+terminfo[kcuf1]} )); then + bindkey -M $keymap "^[${terminfo[kcuf1]}" dirhistory_zle_dirhistory_future # urxvt + fi +done + +# +# HIERARCHY Implemented in this section, in case someone wants to split it to another plugin if it clashes bindings +# + +# Move up in hierarchy +function dirhistory_up() { + cd .. || return 1 +} + +# Move down in hierarchy +function dirhistory_down() { + cd "$(find . -mindepth 1 -maxdepth 1 -type d | sort -n | head -n 1)" || return 1 +} + + +# Bind keys to hierarchy navigation +function dirhistory_zle_dirhistory_up() { + zle .kill-buffer # Erase current line in buffer + dirhistory_up + zle .accept-line +} + +function dirhistory_zle_dirhistory_down() { + zle .kill-buffer # Erase current line in buffer + dirhistory_down + zle .accept-line +} + +zle -N dirhistory_zle_dirhistory_up +zle -N dirhistory_zle_dirhistory_down + +for keymap in emacs vicmd viins; do + # dirhistory_up + bindkey -M $keymap "\e[3A" dirhistory_zle_dirhistory_up # xterm in normal mode + bindkey -M $keymap "\e[1;3A" dirhistory_zle_dirhistory_up # xterm in normal mode + bindkey -M $keymap "\e\e[A" dirhistory_zle_dirhistory_up # Putty + bindkey -M $keymap "\eO3A" dirhistory_zle_dirhistory_up # GNU screen + + case "$TERM_PROGRAM" in + Apple_Terminal) bindkey -M $keymap "^[[A" dirhistory_zle_dirhistory_up ;; # Terminal.app + iTerm.app) bindkey -M $keymap "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2 + esac + + if (( ${+terminfo[kcuu1]} )); then + bindkey -M $keymap "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt + fi + + # dirhistory_down + bindkey -M $keymap "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode + bindkey -M $keymap "\e[1;3B" dirhistory_zle_dirhistory_down # xterm in normal mode + bindkey -M $keymap "\e\e[B" dirhistory_zle_dirhistory_down # Putty + bindkey -M $keymap "\eO3B" dirhistory_zle_dirhistory_down # GNU screen + + case "$TERM_PROGRAM" in + Apple_Terminal) bindkey -M $keymap "^[[B" dirhistory_zle_dirhistory_down ;; # Terminal.app + iTerm.app) bindkey -M $keymap "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2 + esac + + if (( ${+terminfo[kcud1]} )); then + bindkey -M $keymap "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt + fi +done + +unset keymap \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh new file mode 100644 index 00000000..358ebb31 --- /dev/null +++ b/share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh @@ -0,0 +1,137 @@ +alias x=extract + +extract() { + setopt localoptions noautopushd + + if (( $# == 0 )); then + cat >&2 <<'EOF' +Usage: extract [-option] [file ...] + +Options: + -r, --remove Remove archive after unpacking. +EOF + fi + + local remove_archive=1 + if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then + remove_archive=0 + shift + fi + + local pwd="$PWD" + while (( $# > 0 )); do + if [[ ! -f "$1" ]]; then + echo "extract: '$1' is not a valid file" >&2 + shift + continue + fi + + local success=0 + local file="$1" full_path="${1:A}" + local extract_dir="${1:t:r}" + + # Remove the .tar extension if the file name is .tar.* + if [[ $extract_dir =~ '\.tar$' ]]; then + extract_dir="${extract_dir:r}" + fi + + # If there's a file or directory with the same name as the archive + # add a random string to the end of the extract directory + if [[ -e "$extract_dir" ]]; then + local rnd="${(L)"${$(( [##36]$RANDOM*$RANDOM ))}":1:5}" + extract_dir="${extract_dir}-${rnd}" + fi + + # Create an extraction directory based on the file name + command mkdir -p "$extract_dir" + builtin cd -q "$extract_dir" + echo "extract: extracting to $extract_dir" >&2 + + case "${file:l}" in + (*.tar.gz|*.tgz) + (( $+commands[pigz] )) && { tar -I pigz -xvf "$full_path" } || tar zxvf "$full_path" ;; + (*.tar.bz2|*.tbz|*.tbz2) + (( $+commands[pbzip2] )) && { tar -I pbzip2 -xvf "$full_path" } || tar xvjf "$full_path" ;; + (*.tar.xz|*.txz) + (( $+commands[pixz] )) && { tar -I pixz -xvf "$full_path" } || { + tar --xz --help &> /dev/null \ + && tar --xz -xvf "$full_path" \ + || xzcat "$full_path" | tar xvf - } ;; + (*.tar.zma|*.tlz) + tar --lzma --help &> /dev/null \ + && tar --lzma -xvf "$full_path" \ + || lzcat "$full_path" | tar xvf - ;; + (*.tar.zst|*.tzst) + tar --zstd --help &> /dev/null \ + && tar --zstd -xvf "$full_path" \ + || zstdcat "$full_path" | tar xvf - ;; + (*.tar) tar xvf "$full_path" ;; + (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;; + (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;; + (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;; + (*.gz) (( $+commands[pigz] )) && pigz -cdk "$full_path" > "${file:t:r}" || gunzip -ck "$full_path" > "${file:t:r}" ;; + (*.bz2) (( $+commands[pbzip2] )) && pbzip2 -d "$full_path" || bunzip2 "$full_path" ;; + (*.xz) unxz "$full_path" ;; + (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;; + (*.lz4) lz4 -d "$full_path" ;; + (*.lzma) unlzma "$full_path" ;; + (*.z) uncompress "$full_path" ;; + (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$full_path" ;; + (*.rar) unrar x -ad "$full_path" ;; + (*.rpm) + rpm2cpio "$full_path" | cpio --quiet -id ;; + (*.7z | *.7z.[0-9]*) 7za x "$full_path" ;; + (*.deb) + command mkdir -p "control" "data" + ar vx "$full_path" > /dev/null + builtin cd -q control; extract ../control.tar.* + builtin cd -q ../data; extract ../data.tar.* + builtin cd -q ..; command rm *.tar.* debian-binary ;; + (*.zst) unzstd --stdout "$full_path" > "${file:t:r}" ;; + (*.cab|*.exe) cabextract "$full_path" ;; + (*.cpio|*.obscpio) cpio -idmvF "$full_path" ;; + (*.zpaq) zpaq x "$full_path" ;; + (*.zlib) zlib-flate -uncompress < "$full_path" > "${file:r}" ;; + (*) + echo "extract: '$file' cannot be extracted" >&2 + success=1 ;; + esac + + (( success = success > 0 ? success : $? )) + (( success == 0 && remove_archive == 0 )) && command rm "$full_path" + shift + + # Go back to original working directory + builtin cd -q "$pwd" + + # If content of extract dir is a single directory, move its contents up + # Glob flags: + # - D: include files starting with . + # - N: no error if directory is empty + # - Y2: at most give 2 files + local -a content + content=("${extract_dir}"/*(DNY2)) + if [[ ${#content} -eq 1 && -e "${content[1]}" ]]; then + # The extracted file/folder (${content[1]}) may have the same name as $extract_dir + # If so, we need to rename it to avoid conflicts in a 3-step process + # + # 1. Move and rename the extracted file/folder to a temporary random name + # 2. Delete the empty folder + # 3. Rename the extracted file/folder to the original name + if [[ "${content[1]:t}" == "$extract_dir" ]]; then + # =(:) gives /tmp/zsh, with :t it gives zsh + local tmp_name==(:); tmp_name="${tmp_name:t}" + command mv "${content[1]}" "$tmp_name" \ + && command rmdir "$extract_dir" \ + && command mv "$tmp_name" "$extract_dir" + # Otherwise, if the extracted folder name already exists in the current + # directory (because of a previous file / folder), keep the extract_dir + elif [[ ! -e "${content[1]:t}" ]]; then + command mv "${content[1]}" . \ + && command rmdir "$extract_dir" + fi + elif [[ ${#content} -eq 0 ]]; then + command rmdir "$extract_dir" + fi + done +} \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh new file mode 100644 index 00000000..42255cd7 --- /dev/null +++ b/share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh @@ -0,0 +1,108 @@ +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# sudo or sudo -e (replacement for sudoedit) will be inserted before the command +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Dongweiming +# * Subhaditya Nath +# * Marc Cornellà +# * Carlo Sala +# +# ------------------------------------------------------------------------------ + +__sudo-replace-buffer() { + local old=$1 new=$2 space=${2:+ } + + # if the cursor is positioned in the $old part of the text, make + # the substitution and leave the cursor after the $new text + if [[ $CURSOR -le ${#old} ]]; then + BUFFER="${new}${space}${BUFFER#$old }" + CURSOR=${#new} + # otherwise just replace $old with $new in the text before the cursor + else + LBUFFER="${new}${space}${LBUFFER#$old }" + fi +} + +sudo-command-line() { + # If line is empty, get the last run command from history + [[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" + + # Save beginning space + local WHITESPACE="" + if [[ ${LBUFFER:0:1} = " " ]]; then + WHITESPACE=" " + LBUFFER="${LBUFFER:1}" + fi + + { + # If $SUDO_EDITOR or $VISUAL are defined, then use that as $EDITOR + # Else use the default $EDITOR + local EDITOR=${SUDO_EDITOR:-${VISUAL:-$EDITOR}} + + # If $EDITOR is not set, just toggle the sudo prefix on and off + if [[ -z "$EDITOR" ]]; then + case "$BUFFER" in + sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "" ;; + sudo\ *) __sudo-replace-buffer "sudo" "" ;; + *) LBUFFER="sudo $LBUFFER" ;; + esac + return + fi + + # Check if the typed command is really an alias to $EDITOR + + # Get the first part of the typed command + local cmd="${${(Az)BUFFER}[1]}" + # Get the first part of the alias of the same name as $cmd, or $cmd if no alias matches + local realcmd="${${(Az)aliases[$cmd]}[1]:-$cmd}" + # Get the first part of the $EDITOR command ($EDITOR may have arguments after it) + local editorcmd="${${(Az)EDITOR}[1]}" + + # Note: ${var:c} makes a $PATH search and expands $var to the full path + # The if condition is met when: + # - $realcmd is '$EDITOR' + # - $realcmd is "cmd" and $EDITOR is "cmd" + # - $realcmd is "cmd" and $EDITOR is "cmd --with --arguments" + # - $realcmd is "/path/to/cmd" and $EDITOR is "cmd" + # - $realcmd is "/path/to/cmd" and $EDITOR is "/path/to/cmd" + # or + # - $realcmd is "cmd" and $EDITOR is "cmd" + # - $realcmd is "cmd" and $EDITOR is "/path/to/cmd" + # or + # - $realcmd is "cmd" and $EDITOR is /alternative/path/to/cmd that appears in $PATH + if [[ "$realcmd" = (\$EDITOR|$editorcmd|${editorcmd:c}) \ + || "${realcmd:c}" = ($editorcmd|${editorcmd:c}) ]] \ + || builtin which -a "$realcmd" | command grep -Fx -q "$editorcmd"; then + __sudo-replace-buffer "$cmd" "sudo -e" + return + fi + + # Check for editor commands in the typed command and replace accordingly + case "$BUFFER" in + $editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudo -e" ;; + \$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudo -e" ;; + sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "$EDITOR" ;; + sudo\ *) __sudo-replace-buffer "sudo" "" ;; + *) LBUFFER="sudo $LBUFFER" ;; + esac + } always { + # Preserve beginning space + LBUFFER="${WHITESPACE}${LBUFFER}" + + # Redisplay edit buffer (compatibility with zsh-syntax-highlighting) + zle && zle redisplay # only run redisplay if zle is enabled + } +} + +zle -N sudo-command-line + +# Defined shortcut keys: [Esc] [Esc] +bindkey -M emacs '\e\e' sudo-command-line +bindkey -M vicmd '\e\e' sudo-command-line +bindkey -M viins '\e\e' sudo-command-line \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh new file mode 100644 index 00000000..db44dea8 --- /dev/null +++ b/share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh @@ -0,0 +1,279 @@ +#!/bin/zsh + +export YSU_VERSION='1.7.3' + +if ! type "tput" > /dev/null; then + printf "WARNING: tput command not found on your PATH.\n" + printf "zsh-you-should-use will fallback to uncoloured messages\n" +else + NONE="$(tput sgr0)" + BOLD="$(tput bold)" + RED="$(tput setaf 1)" + YELLOW="$(tput setaf 3)" + PURPLE="$(tput setaf 5)" +fi + +function check_alias_usage() { + # Optional parameter that limits how far back history is checked + # I've chosen a large default value instead of bypassing tail because it's simpler + # TODO: this should probably be cleaned up + local limit="${1:-9000000000000000}" + local key + + declare -A usage + for key in "${(@k)aliases}"; do + usage[$key]=0 + done + + # TODO: + # Handle and (&&) + (&) + # others? watch, time etc... + + local current=0 + local total=$(wc -l < "$HISTFILE") + if [[ $total -gt $limit ]]; then + total=$limit + fi + + <"$HISTFILE" | tail "-$limit" | cut -d";" -f2 | while read line; do + local entry + for entry in ${(@s/|/)line}; do + # Remove leading whitespace + # TODO: This is extremely slow + entry="$(echo "$entry" | sed -e 's/^ *//')" + + # We only care about the first word because that's all aliases work with + # (this does not count global and git aliases) + local word=${entry[(w)1]} + if [[ -n ${usage[$word]} ]]; then + local prev=$usage[$word] + let "prev = prev + 1 " + usage[$word]=$prev + fi + done + + # print current progress + let "current = current + 1" + printf "[$current/$total]\r" + done + # Clear all previous line output + printf "\r\033[K" + + # Print ordered usage + for key in ${(k)usage}; do + echo "${usage[$key]}: $key='${aliases[$key]}'" + done | sort -rn -k1 +} + +# Writing to a buffer rather than directly to stdout/stderr allows us to decide +# if we want to write the reminder message before or after a command has been executed +function _write_ysu_buffer() { + _YSU_BUFFER+="$@" + + # Maintain historical behaviour by default + local position="${YSU_MESSAGE_POSITION:-before}" + if [[ "$position" = "before" ]]; then + _flush_ysu_buffer + elif [[ "$position" != "after" ]]; then + (>&2 printf "${RED}${BOLD}Unknown value for YSU_MESSAGE_POSITION '$position'. ") + (>&2 printf "Expected value 'before' or 'after'${NONE}\n") + _flush_ysu_buffer + fi +} + +function _flush_ysu_buffer() { + # It's important to pass $_YSU_BUFFER to printfs first argument + # because otherwise all escape codes will not printed correctly + (>&2 printf "$_YSU_BUFFER") + _YSU_BUFFER="" +} + +function ysu_message() { + local DEFAULT_MESSAGE_FORMAT="${BOLD}${YELLOW}\ +Found existing %alias_type for ${PURPLE}\"%command\"${YELLOW}. \ +You should use: ${PURPLE}\"%alias\"${NONE}" + + local alias_type_arg="${1}" + local command_arg="${2}" + local alias_arg="${3}" + + # Escape arguments which will be interpreted by printf incorrectly + # unfortunately there does not seem to be a nice way to put this into + # a function because returning the values requires to be done by printf/echo!! + command_arg="${command_arg//\%/%%}" + command_arg="${command_arg//\\/\\\\}" + + local MESSAGE="${YSU_MESSAGE_FORMAT:-"$DEFAULT_MESSAGE_FORMAT"}" + MESSAGE="${MESSAGE//\%alias_type/$alias_type_arg}" + MESSAGE="${MESSAGE//\%command/$command_arg}" + MESSAGE="${MESSAGE//\%alias/$alias_arg}" + + _write_ysu_buffer "$MESSAGE\n" +} + + +# Prevent command from running if hardcore mode enabled +function _check_ysu_hardcore() { + if [[ "$YSU_HARDCORE" = 1 ]]; then + _write_ysu_buffer "${BOLD}${RED}You Should Use hardcore mode enabled. Use your aliases!${NONE}\n" + kill -s INT $$ + fi +} + + +function _check_git_aliases() { + local typed="$1" + local expanded="$2" + + # sudo will use another user's profile and so aliases would not apply + if [[ "$typed" = "sudo "* ]]; then + return + fi + + if [[ "$typed" = "git "* ]]; then + local found=false + git config --get-regexp "^alias\..+$" | sort | while read key value; do + key="${key#alias.}" + + if [[ "$expanded" = "git $value" || "$expanded" = "git $value "* ]]; then + ysu_message "git alias" "$value" "git $key" + found=true + fi + done + + if $found; then + _check_ysu_hardcore + fi + fi +} + + +function _check_global_aliases() { + local typed="$1" + local expanded="$2" + + local found=false + local tokens + local key + local value + local entry + + # sudo will use another user's profile and so aliases would not apply + if [[ "$typed" = "sudo "* ]]; then + return + fi + + alias -g | sort | while read entry; do + tokens=("${(@s/=/)entry}") + key="${tokens[1]}" + # Need to remove leading and trailing ' if they exist + value="${(Q)tokens[2]}" + + # Skip ignored global aliases + if [[ ${YSU_IGNORED_GLOBAL_ALIASES[(r)$key]} == "$key" ]]; then + continue + fi + + if [[ "$typed" = *" $value "* || \ + "$typed" = *" $value" || \ + "$typed" = "$value "* || \ + "$typed" = "$value" ]]; then + ysu_message "global alias" "$value" "$key" + found=true + fi + done + + if $found; then + _check_ysu_hardcore + fi +} + + +function _check_aliases() { + local typed="$1" + local expanded="$2" + + local found_aliases + found_aliases=() + local best_match="" + local best_match_value="" + local key + local value + + # sudo will use another user's profile and so aliases would not apply + if [[ "$typed" = "sudo "* ]]; then + return + fi + + # Find alias matches + for key in "${(@k)aliases}"; do + value="${aliases[$key]}" + + # Skip ignored aliases + if [[ ${YSU_IGNORED_ALIASES[(r)$key]} == "$key" ]]; then + continue + fi + + if [[ "$typed" = "$value" || \ + "$typed" = "$value "* ]]; then + + # if the alias longer or the same length as its command + # we assume that it is there to cater for typos. + # If not, then the alias would not save any time + # for the user and so doesn't hold much value anyway + if [[ "${#value}" -gt "${#key}" ]]; then + + found_aliases+="$key" + + # Match aliases to longest portion of command + if [[ "${#value}" -gt "${#best_match_value}" ]]; then + best_match="$key" + best_match_value="$value" + # on equal length, choose the shortest alias + elif [[ "${#value}" -eq "${#best_match}" && ${#key} -lt "${#best_match}" ]]; then + best_match="$key" + best_match_value="$value" + fi + fi + fi + done + + # Print result matches based on current mode + if [[ "$YSU_MODE" = "ALL" ]]; then + for key in ${(@ok)found_aliases}; do + value="${aliases[$key]}" + ysu_message "alias" "$value" "$key" + done + + elif [[ (-z "$YSU_MODE" || "$YSU_MODE" = "BESTMATCH") && -n "$best_match" ]]; then + # make sure that the best matched alias has not already + # been typed by the user + value="${aliases[$best_match]}" + if [[ "$typed" = "$best_match" || "$typed" = "$best_match "* ]]; then + return + fi + ysu_message "alias" "$value" "$best_match" + fi + + if [[ -n "$found_aliases" ]]; then + _check_ysu_hardcore + fi +} + +function disable_you_should_use() { + add-zsh-hook -D preexec _check_aliases + add-zsh-hook -D preexec _check_global_aliases + add-zsh-hook -D preexec _check_git_aliases + add-zsh-hook -D precmd _flush_ysu_buffer +} + +function enable_you_should_use() { + disable_you_should_use # Delete any possible pre-existing hooks + add-zsh-hook preexec _check_aliases + add-zsh-hook preexec _check_global_aliases + add-zsh-hook preexec _check_git_aliases + add-zsh-hook precmd _flush_ysu_buffer +} + +autoload -Uz add-zsh-hook +enable_you_should_use From 7a93e28ac238e564aa33675e63af89020fc78eae Mon Sep 17 00:00:00 2001 From: Oblivionis <182329535+0blivi0nis@users.noreply.github.com> Date: Wed, 25 Sep 2024 20:06:55 -0700 Subject: [PATCH 3/8] Instead of shipping plugins baked in with the dotfiles, added commands to shell.sh to install the plugins directly from source if the user chooses zsh. --- share/dotfiles/.config/ml4w/scripts/shell.sh | 107 ++++++- .../plugins/colored-man-pages.plugin.zsh | 54 ---- .../plugins/command-not-found.plugin.zsh | 70 ----- .../zshrc/plugins/dirhistory.plugin.zsh | 225 -------------- .../.config/zshrc/plugins/extract.plugin.zsh | 137 --------- .../.config/zshrc/plugins/sudo.plugin.zsh | 108 ------- .../zshrc/plugins/you-should-use.plugin.zsh | 279 ------------------ 7 files changed, 103 insertions(+), 877 deletions(-) delete mode 100644 share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh delete mode 100644 share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh delete mode 100644 share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh delete mode 100644 share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh delete mode 100644 share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh delete mode 100644 share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh diff --git a/share/dotfiles/.config/ml4w/scripts/shell.sh b/share/dotfiles/.config/ml4w/scripts/shell.sh index f3c743a0..259d9942 100755 --- a/share/dotfiles/.config/ml4w/scripts/shell.sh +++ b/share/dotfiles/.config/ml4w/scripts/shell.sh @@ -44,15 +44,23 @@ if [[ $shell == "bash" ]] ;then # ----------------------------------------------------- elif [[ $shell == "zsh" ]] ;then - # Change shell to shh + # Change shell to zsh while ! chsh -s $(which zsh); do echo "ERROR: Authentication failed. Please enter the correct password." sleep 1 done echo ":: Shell is now zsh." + # Check for plugins directory + if [ ! -d "$HOME/.config/zshrc/plugins" ]; then + echo ":: Making ZSH Plugin directory" + mkdir -p $HOME/.config/zshrc/plugins + else + echo ":: ZSH Plugin directory already exists" + fi + # Installing zsh-autosuggestions - if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then + if [ ! -d "$HOME/.config/zshrc/plugins/zsh-autosuggestions" ]; then echo ":: Installing zsh-autosuggestions" git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.config/zshrc/plugins/zsh-autosuggestions else @@ -60,7 +68,7 @@ elif [[ $shell == "zsh" ]] ;then fi # Installing zsh-syntax-highlighting - if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]; then + if [ ! -d "$HOME/.config/zshrc/plugins/zsh-syntax-highlighting" ]; then echo ":: Installing zsh-syntax-highlighting" git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.config/zshrc/plugins/zsh-syntax-highlighting else @@ -68,7 +76,7 @@ elif [[ $shell == "zsh" ]] ;then fi # Installing fast-syntax-highlighting - if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/fast-syntax-highlighting" ]; then + if [ ! -d "$HOME/.config/zshrc/plugins/fast-syntax-highlighting" ]; then echo ":: Installing fast-syntax-highlighting" git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git $HOME/.config/zshrc/plugins/fast-syntax-highlighting else @@ -83,6 +91,97 @@ elif [[ $shell == "zsh" ]] ;then echo ":: zsh-completions already installed" fi + # Install zsh-plugin-git + if [ ! -f "$HOME/.config/zshrc/plugins/git.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-git" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/git/git.plugin.zsh -o $HOME/.config/zshrc/plugins/git.plugin.zsh + else + echo ":: zsh-plugin-git already installed" + fi + + # Install zsh-plugin-sudo + if [ ! -f "$HOME/.config/zshrc/plugins/sudo.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-sudo" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/sudo/sudo.plugin.zsh -o $HOME/.config/zshrc/plugins/sudo.plugin.zsh + else + echo ":: zsh-plugin-sudo already installed" + fi + + # Install zsh-plugin-web-search + if [ ! -f "$HOME/.config/zshrc/plugins/web-search.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-web-search" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/web-search/web-search.plugin.zsh -o $HOME/.config/zshrc/plugins/web-search.plugin.zsh + else + echo ":: zsh-plugin-web-search already installed" + fi + + # Install zsh-plugin-archlinux + if [ ! -f "$HOME/.config/zshrc/plugins/archlinux.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-archlinux" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/archlinux/archlinux.plugin.zsh -o $HOME/.config/zshrc/plugins/archlinux.plugin.zsh + else + echo ":: zsh-plugin-archlinux already installed" + fi + + # Install zsh-plugin-copyfile + if [ ! -f "$HOME/.config/zshrc/plugins/copyfile.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-copyfile" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/copyfile/copyfile.plugin.zsh -o $HOME/.config/zshrc/plugins/copyfile.plugin.zsh + else + echo ":: zsh-plugin-copyfile already installed" + fi + + # Install zsh-plugin-copybuffer + if [ ! -f "$HOME/.config/zshrc/plugins/copybuffer.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-copybuffer" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/copybuffer/copybuffer.plugin.zsh -o $HOME/.config/zshrc/plugins/copybuffer.plugin.zsh + else + echo ":: zsh-plugin-copybuffer already installed" + fi + + # Install zsh-plugin-dirhistory + if [ ! -f "$HOME/.config/zshrc/plugins/dirhistory.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-dirhistory" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/dirhistory/dirhistory.plugin.zsh -o $HOME/.config/zshrc/plugins/dirhistory.plugin.zsh + else + echo ":: zsh-plugin-dirhistory already installed" + fi + + # Install zsh-plugin-colored-man-pages + if [ ! -f "$HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-colored-man-pages" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/colored-man-pages/colored-man-pages.plugin.zsh -o $HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh + else + echo ":: zsh-plugin-colored-man-pages already installed" + fi + + # Install zsh-plugin-command-not-found + if [ ! -f "$HOME/.config/zshrc/plugins/command-not-found.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-command-not-found" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/command-not-found/command-not-found.plugin.zsh -o $HOME/.config/zshrc/plugins/command-not-found.plugin.zsh + else + echo ":: zsh-plugin-command-not-found already installed" + fi + + # Install zsh-plugin-extract + if [ ! -f "$HOME/.config/zshrc/plugins/extract.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-extract" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/extract/extract.plugin.zsh -o $HOME/.config/zshrc/plugins/extract.plugin.zsh + else + echo ":: zsh-plugin-extract already installed" + fi + + # Install zsh-plugin-you-should-use + if [ ! -f "$HOME/.config/zshrc/plugins/you-should-use.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-you-should-use" + curl https://raw.githubusercontent.com/MichaelAquilina/zsh-you-should-use/refs/heads/master/you-should-use.plugin.zsh -o $HOME/.config/zshrc/plugins/you-should-use.plugin.zsh + else + echo ":: zsh-plugin-you-should-use already installed" + fi + + + + # Install pkgfile if needed (for command not found) if ! command -v pkgfile &> /dev/null; then echo ":: Installing pkgfile" diff --git a/share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh deleted file mode 100644 index 57facbb5..00000000 --- a/share/dotfiles/.config/zshrc/plugins/colored-man-pages.plugin.zsh +++ /dev/null @@ -1,54 +0,0 @@ -# Requires colors autoload. -# See termcap(5). - -# Set up once, and then reuse. This way it supports user overrides after the -# plugin is loaded. -typeset -AHg less_termcap - -# bold & blinking mode -less_termcap[mb]="${fg_bold[red]}" -less_termcap[md]="${fg_bold[red]}" -less_termcap[me]="${reset_color}" -# standout mode -less_termcap[so]="${fg_bold[yellow]}${bg[blue]}" -less_termcap[se]="${reset_color}" -# underlining -less_termcap[us]="${fg_bold[green]}" -less_termcap[ue]="${reset_color}" - -# Handle $0 according to the standard: -# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html -0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" -0="${${(M)0:#/*}:-$PWD/$0}" - -# Absolute path to this file's directory. -typeset -g __colored_man_pages_dir="${0:A:h}" - -function colored() { - local -a environment - - # Convert associative array to plain array of NAME=VALUE items. - local k v - for k v in "${(@kv)less_termcap}"; do - environment+=( "LESS_TERMCAP_${k}=${v}" ) - done - - # Prefer `less` whenever available, since we specifically configured - # environment for it. - environment+=( PAGER="${commands[less]:-$PAGER}" ) - environment+=( GROFF_NO_SGR=1 ) - - # See ./nroff script. - if [[ "$OSTYPE" = solaris* ]]; then - environment+=( PATH="${__colored_man_pages_dir}:$PATH" ) - fi - - command env $environment "$@" -} - -# Colorize man and dman/debman (from debian-goodies) -function man \ - dman \ - debman { - colored $0 "$@" -} diff --git a/share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh deleted file mode 100644 index 0034b0ad..00000000 --- a/share/dotfiles/.config/zshrc/plugins/command-not-found.plugin.zsh +++ /dev/null @@ -1,70 +0,0 @@ -## Platforms with a built-in command-not-found handler init file - -for file ( - # Arch Linux. Must have pkgfile installed: https://wiki.archlinux.org/index.php/Pkgfile#Command_not_found - /usr/share/doc/pkgfile/command-not-found.zsh - # Homebrew: https://github.com/Homebrew/homebrew-command-not-found - /opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh - /usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh - /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh -); do - if [[ -r "$file" ]]; then - source "$file" - unset file - return 0 - fi -done -unset file - - -## Platforms with manual command_not_found_handler() setup - -# Debian and derivatives: https://launchpad.net/ubuntu/+source/command-not-found -if [[ -x /usr/lib/command-not-found || -x /usr/share/command-not-found/command-not-found ]]; then - command_not_found_handler() { - if [[ -x /usr/lib/command-not-found ]]; then - /usr/lib/command-not-found -- "$1" - return $? - elif [[ -x /usr/share/command-not-found/command-not-found ]]; then - /usr/share/command-not-found/command-not-found -- "$1" - return $? - else - printf "zsh: command not found: %s\n" "$1" >&2 - return 127 - fi - } -fi - -# Fedora: https://fedoraproject.org/wiki/Features/PackageKitCommandNotFound -if [[ -x /usr/libexec/pk-command-not-found ]]; then - command_not_found_handler() { - if [[ -S /var/run/dbus/system_bus_socket && -x /usr/libexec/packagekitd ]]; then - /usr/libexec/pk-command-not-found "$@" - return $? - fi - - printf "zsh: command not found: %s\n" "$1" >&2 - return 127 - } -fi - -# NixOS: https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/programs/command-not-found -if [[ -x /run/current-system/sw/bin/command-not-found ]]; then - command_not_found_handler() { - /run/current-system/sw/bin/command-not-found "$@" - } -fi - -# Termux: https://github.com/termux/command-not-found -if [[ -x /data/data/com.termux/files/usr/libexec/termux/command-not-found ]]; then - command_not_found_handler() { - /data/data/com.termux/files/usr/libexec/termux/command-not-found "$1" - } -fi - -# SUSE and derivates: https://www.unix.com/man-page/suse/1/command-not-found/ -if [[ -x /usr/bin/command-not-found ]]; then - command_not_found_handler() { - /usr/bin/command-not-found "$1" - } -fi \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh deleted file mode 100644 index d90b7f8e..00000000 --- a/share/dotfiles/.config/zshrc/plugins/dirhistory.plugin.zsh +++ /dev/null @@ -1,225 +0,0 @@ -## -# Navigate directory history using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories -# that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. -# -# Navigate directory hierarchy using ALT-UP and ALT-DOWN. -# ALT-UP moves to higher hierarchy (cd ..) -# ALT-DOWN moves into the first directory found in alphabetical order -# - -dirhistory_past=($PWD) -dirhistory_future=() -export dirhistory_past -export dirhistory_future - -export DIRHISTORY_SIZE=30 - -# Pop the last element of dirhistory_past. -# Pass the name of the variable to return the result in. -# Returns the element if the array was not empty, -# otherwise returns empty string. -function pop_past() { - setopt localoptions no_ksh_arrays - if [[ $#dirhistory_past -gt 0 ]]; then - typeset -g $1="${dirhistory_past[$#dirhistory_past]}" - dirhistory_past[$#dirhistory_past]=() - fi -} - -function pop_future() { - setopt localoptions no_ksh_arrays - if [[ $#dirhistory_future -gt 0 ]]; then - typeset -g $1="${dirhistory_future[$#dirhistory_future]}" - dirhistory_future[$#dirhistory_future]=() - fi -} - -# Push a new element onto the end of dirhistory_past. If the size of the array -# is >= DIRHISTORY_SIZE, the array is shifted -function push_past() { - setopt localoptions no_ksh_arrays - if [[ $#dirhistory_past -ge $DIRHISTORY_SIZE ]]; then - shift dirhistory_past - fi - if [[ $#dirhistory_past -eq 0 || $dirhistory_past[$#dirhistory_past] != "$1" ]]; then - dirhistory_past+=($1) - fi -} - -function push_future() { - setopt localoptions no_ksh_arrays - if [[ $#dirhistory_future -ge $DIRHISTORY_SIZE ]]; then - shift dirhistory_future - fi - if [[ $#dirhistory_future -eq 0 || $dirhistory_futuret[$#dirhistory_future] != "$1" ]]; then - dirhistory_future+=($1) - fi -} - -# Called by zsh when directory changes -autoload -U add-zsh-hook -add-zsh-hook chpwd chpwd_dirhistory -function chpwd_dirhistory() { - push_past $PWD - # If DIRHISTORY_CD is not set... - if [[ -z "${DIRHISTORY_CD+x}" ]]; then - # ... clear future. - dirhistory_future=() - fi -} - -function dirhistory_cd(){ - DIRHISTORY_CD="1" - cd $1 - unset DIRHISTORY_CD -} - -# Move backward in directory history -function dirhistory_back() { - local cw="" - local d="" - # Last element in dirhistory_past is the cwd. - - pop_past cw - if [[ "" == "$cw" ]]; then - # Someone overwrote our variable. Recover it. - dirhistory_past=($PWD) - return - fi - - pop_past d - if [[ "" != "$d" ]]; then - dirhistory_cd $d - push_future $cw - else - push_past $cw - fi -} - - -# Move forward in directory history -function dirhistory_forward() { - local d="" - - pop_future d - if [[ "" != "$d" ]]; then - dirhistory_cd $d - push_past $d - fi -} - - -# Bind keys to history navigation -function dirhistory_zle_dirhistory_back() { - # Erase current line in buffer - zle .kill-buffer - dirhistory_back - zle .accept-line -} - -function dirhistory_zle_dirhistory_future() { - # Erase current line in buffer - zle .kill-buffer - dirhistory_forward - zle .accept-line -} - -zle -N dirhistory_zle_dirhistory_back -zle -N dirhistory_zle_dirhistory_future - -for keymap in emacs vicmd viins; do - # dirhistory_back - bindkey -M $keymap "\e[3D" dirhistory_zle_dirhistory_back # xterm in normal mode - bindkey -M $keymap "\e[1;3D" dirhistory_zle_dirhistory_back # xterm in normal mode - bindkey -M $keymap "\e\e[D" dirhistory_zle_dirhistory_back # Putty - bindkey -M $keymap "\eO3D" dirhistory_zle_dirhistory_back # GNU screen - - case "$TERM_PROGRAM" in - Apple_Terminal) bindkey -M $keymap "^[b" dirhistory_zle_dirhistory_back ;; # Terminal.app - iTerm.app) bindkey -M $keymap "^[^[[D" dirhistory_zle_dirhistory_back ;; # iTerm2 - esac - - if (( ${+terminfo[kcub1]} )); then - bindkey -M $keymap "^[${terminfo[kcub1]}" dirhistory_zle_dirhistory_back # urxvt - fi - - # dirhistory_future - bindkey -M $keymap "\e[3C" dirhistory_zle_dirhistory_future # xterm in normal mode - bindkey -M $keymap "\e[1;3C" dirhistory_zle_dirhistory_future # xterm in normal mode - bindkey -M $keymap "\e\e[C" dirhistory_zle_dirhistory_future # Putty - bindkey -M $keymap "\eO3C" dirhistory_zle_dirhistory_future # GNU screen - - case "$TERM_PROGRAM" in - Apple_Terminal) bindkey -M $keymap "^[f" dirhistory_zle_dirhistory_future ;; # Terminal.app - iTerm.app) bindkey -M $keymap "^[^[[C" dirhistory_zle_dirhistory_future ;; # iTerm2 - esac - - if (( ${+terminfo[kcuf1]} )); then - bindkey -M $keymap "^[${terminfo[kcuf1]}" dirhistory_zle_dirhistory_future # urxvt - fi -done - -# -# HIERARCHY Implemented in this section, in case someone wants to split it to another plugin if it clashes bindings -# - -# Move up in hierarchy -function dirhistory_up() { - cd .. || return 1 -} - -# Move down in hierarchy -function dirhistory_down() { - cd "$(find . -mindepth 1 -maxdepth 1 -type d | sort -n | head -n 1)" || return 1 -} - - -# Bind keys to hierarchy navigation -function dirhistory_zle_dirhistory_up() { - zle .kill-buffer # Erase current line in buffer - dirhistory_up - zle .accept-line -} - -function dirhistory_zle_dirhistory_down() { - zle .kill-buffer # Erase current line in buffer - dirhistory_down - zle .accept-line -} - -zle -N dirhistory_zle_dirhistory_up -zle -N dirhistory_zle_dirhistory_down - -for keymap in emacs vicmd viins; do - # dirhistory_up - bindkey -M $keymap "\e[3A" dirhistory_zle_dirhistory_up # xterm in normal mode - bindkey -M $keymap "\e[1;3A" dirhistory_zle_dirhistory_up # xterm in normal mode - bindkey -M $keymap "\e\e[A" dirhistory_zle_dirhistory_up # Putty - bindkey -M $keymap "\eO3A" dirhistory_zle_dirhistory_up # GNU screen - - case "$TERM_PROGRAM" in - Apple_Terminal) bindkey -M $keymap "^[[A" dirhistory_zle_dirhistory_up ;; # Terminal.app - iTerm.app) bindkey -M $keymap "^[^[[A" dirhistory_zle_dirhistory_up ;; # iTerm2 - esac - - if (( ${+terminfo[kcuu1]} )); then - bindkey -M $keymap "^[${terminfo[kcuu1]}" dirhistory_zle_dirhistory_up # urxvt - fi - - # dirhistory_down - bindkey -M $keymap "\e[3B" dirhistory_zle_dirhistory_down # xterm in normal mode - bindkey -M $keymap "\e[1;3B" dirhistory_zle_dirhistory_down # xterm in normal mode - bindkey -M $keymap "\e\e[B" dirhistory_zle_dirhistory_down # Putty - bindkey -M $keymap "\eO3B" dirhistory_zle_dirhistory_down # GNU screen - - case "$TERM_PROGRAM" in - Apple_Terminal) bindkey -M $keymap "^[[B" dirhistory_zle_dirhistory_down ;; # Terminal.app - iTerm.app) bindkey -M $keymap "^[^[[B" dirhistory_zle_dirhistory_down ;; # iTerm2 - esac - - if (( ${+terminfo[kcud1]} )); then - bindkey -M $keymap "^[${terminfo[kcud1]}" dirhistory_zle_dirhistory_down # urxvt - fi -done - -unset keymap \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh deleted file mode 100644 index 358ebb31..00000000 --- a/share/dotfiles/.config/zshrc/plugins/extract.plugin.zsh +++ /dev/null @@ -1,137 +0,0 @@ -alias x=extract - -extract() { - setopt localoptions noautopushd - - if (( $# == 0 )); then - cat >&2 <<'EOF' -Usage: extract [-option] [file ...] - -Options: - -r, --remove Remove archive after unpacking. -EOF - fi - - local remove_archive=1 - if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then - remove_archive=0 - shift - fi - - local pwd="$PWD" - while (( $# > 0 )); do - if [[ ! -f "$1" ]]; then - echo "extract: '$1' is not a valid file" >&2 - shift - continue - fi - - local success=0 - local file="$1" full_path="${1:A}" - local extract_dir="${1:t:r}" - - # Remove the .tar extension if the file name is .tar.* - if [[ $extract_dir =~ '\.tar$' ]]; then - extract_dir="${extract_dir:r}" - fi - - # If there's a file or directory with the same name as the archive - # add a random string to the end of the extract directory - if [[ -e "$extract_dir" ]]; then - local rnd="${(L)"${$(( [##36]$RANDOM*$RANDOM ))}":1:5}" - extract_dir="${extract_dir}-${rnd}" - fi - - # Create an extraction directory based on the file name - command mkdir -p "$extract_dir" - builtin cd -q "$extract_dir" - echo "extract: extracting to $extract_dir" >&2 - - case "${file:l}" in - (*.tar.gz|*.tgz) - (( $+commands[pigz] )) && { tar -I pigz -xvf "$full_path" } || tar zxvf "$full_path" ;; - (*.tar.bz2|*.tbz|*.tbz2) - (( $+commands[pbzip2] )) && { tar -I pbzip2 -xvf "$full_path" } || tar xvjf "$full_path" ;; - (*.tar.xz|*.txz) - (( $+commands[pixz] )) && { tar -I pixz -xvf "$full_path" } || { - tar --xz --help &> /dev/null \ - && tar --xz -xvf "$full_path" \ - || xzcat "$full_path" | tar xvf - } ;; - (*.tar.zma|*.tlz) - tar --lzma --help &> /dev/null \ - && tar --lzma -xvf "$full_path" \ - || lzcat "$full_path" | tar xvf - ;; - (*.tar.zst|*.tzst) - tar --zstd --help &> /dev/null \ - && tar --zstd -xvf "$full_path" \ - || zstdcat "$full_path" | tar xvf - ;; - (*.tar) tar xvf "$full_path" ;; - (*.tar.lz) (( $+commands[lzip] )) && tar xvf "$full_path" ;; - (*.tar.lz4) lz4 -c -d "$full_path" | tar xvf - ;; - (*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$full_path" ;; - (*.gz) (( $+commands[pigz] )) && pigz -cdk "$full_path" > "${file:t:r}" || gunzip -ck "$full_path" > "${file:t:r}" ;; - (*.bz2) (( $+commands[pbzip2] )) && pbzip2 -d "$full_path" || bunzip2 "$full_path" ;; - (*.xz) unxz "$full_path" ;; - (*.lrz) (( $+commands[lrunzip] )) && lrunzip "$full_path" ;; - (*.lz4) lz4 -d "$full_path" ;; - (*.lzma) unlzma "$full_path" ;; - (*.z) uncompress "$full_path" ;; - (*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$full_path" ;; - (*.rar) unrar x -ad "$full_path" ;; - (*.rpm) - rpm2cpio "$full_path" | cpio --quiet -id ;; - (*.7z | *.7z.[0-9]*) 7za x "$full_path" ;; - (*.deb) - command mkdir -p "control" "data" - ar vx "$full_path" > /dev/null - builtin cd -q control; extract ../control.tar.* - builtin cd -q ../data; extract ../data.tar.* - builtin cd -q ..; command rm *.tar.* debian-binary ;; - (*.zst) unzstd --stdout "$full_path" > "${file:t:r}" ;; - (*.cab|*.exe) cabextract "$full_path" ;; - (*.cpio|*.obscpio) cpio -idmvF "$full_path" ;; - (*.zpaq) zpaq x "$full_path" ;; - (*.zlib) zlib-flate -uncompress < "$full_path" > "${file:r}" ;; - (*) - echo "extract: '$file' cannot be extracted" >&2 - success=1 ;; - esac - - (( success = success > 0 ? success : $? )) - (( success == 0 && remove_archive == 0 )) && command rm "$full_path" - shift - - # Go back to original working directory - builtin cd -q "$pwd" - - # If content of extract dir is a single directory, move its contents up - # Glob flags: - # - D: include files starting with . - # - N: no error if directory is empty - # - Y2: at most give 2 files - local -a content - content=("${extract_dir}"/*(DNY2)) - if [[ ${#content} -eq 1 && -e "${content[1]}" ]]; then - # The extracted file/folder (${content[1]}) may have the same name as $extract_dir - # If so, we need to rename it to avoid conflicts in a 3-step process - # - # 1. Move and rename the extracted file/folder to a temporary random name - # 2. Delete the empty folder - # 3. Rename the extracted file/folder to the original name - if [[ "${content[1]:t}" == "$extract_dir" ]]; then - # =(:) gives /tmp/zsh, with :t it gives zsh - local tmp_name==(:); tmp_name="${tmp_name:t}" - command mv "${content[1]}" "$tmp_name" \ - && command rmdir "$extract_dir" \ - && command mv "$tmp_name" "$extract_dir" - # Otherwise, if the extracted folder name already exists in the current - # directory (because of a previous file / folder), keep the extract_dir - elif [[ ! -e "${content[1]:t}" ]]; then - command mv "${content[1]}" . \ - && command rmdir "$extract_dir" - fi - elif [[ ${#content} -eq 0 ]]; then - command rmdir "$extract_dir" - fi - done -} \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh deleted file mode 100644 index 42255cd7..00000000 --- a/share/dotfiles/.config/zshrc/plugins/sudo.plugin.zsh +++ /dev/null @@ -1,108 +0,0 @@ -# ------------------------------------------------------------------------------ -# Description -# ----------- -# -# sudo or sudo -e (replacement for sudoedit) will be inserted before the command -# -# ------------------------------------------------------------------------------ -# Authors -# ------- -# -# * Dongweiming -# * Subhaditya Nath -# * Marc Cornellà -# * Carlo Sala -# -# ------------------------------------------------------------------------------ - -__sudo-replace-buffer() { - local old=$1 new=$2 space=${2:+ } - - # if the cursor is positioned in the $old part of the text, make - # the substitution and leave the cursor after the $new text - if [[ $CURSOR -le ${#old} ]]; then - BUFFER="${new}${space}${BUFFER#$old }" - CURSOR=${#new} - # otherwise just replace $old with $new in the text before the cursor - else - LBUFFER="${new}${space}${LBUFFER#$old }" - fi -} - -sudo-command-line() { - # If line is empty, get the last run command from history - [[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" - - # Save beginning space - local WHITESPACE="" - if [[ ${LBUFFER:0:1} = " " ]]; then - WHITESPACE=" " - LBUFFER="${LBUFFER:1}" - fi - - { - # If $SUDO_EDITOR or $VISUAL are defined, then use that as $EDITOR - # Else use the default $EDITOR - local EDITOR=${SUDO_EDITOR:-${VISUAL:-$EDITOR}} - - # If $EDITOR is not set, just toggle the sudo prefix on and off - if [[ -z "$EDITOR" ]]; then - case "$BUFFER" in - sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "" ;; - sudo\ *) __sudo-replace-buffer "sudo" "" ;; - *) LBUFFER="sudo $LBUFFER" ;; - esac - return - fi - - # Check if the typed command is really an alias to $EDITOR - - # Get the first part of the typed command - local cmd="${${(Az)BUFFER}[1]}" - # Get the first part of the alias of the same name as $cmd, or $cmd if no alias matches - local realcmd="${${(Az)aliases[$cmd]}[1]:-$cmd}" - # Get the first part of the $EDITOR command ($EDITOR may have arguments after it) - local editorcmd="${${(Az)EDITOR}[1]}" - - # Note: ${var:c} makes a $PATH search and expands $var to the full path - # The if condition is met when: - # - $realcmd is '$EDITOR' - # - $realcmd is "cmd" and $EDITOR is "cmd" - # - $realcmd is "cmd" and $EDITOR is "cmd --with --arguments" - # - $realcmd is "/path/to/cmd" and $EDITOR is "cmd" - # - $realcmd is "/path/to/cmd" and $EDITOR is "/path/to/cmd" - # or - # - $realcmd is "cmd" and $EDITOR is "cmd" - # - $realcmd is "cmd" and $EDITOR is "/path/to/cmd" - # or - # - $realcmd is "cmd" and $EDITOR is /alternative/path/to/cmd that appears in $PATH - if [[ "$realcmd" = (\$EDITOR|$editorcmd|${editorcmd:c}) \ - || "${realcmd:c}" = ($editorcmd|${editorcmd:c}) ]] \ - || builtin which -a "$realcmd" | command grep -Fx -q "$editorcmd"; then - __sudo-replace-buffer "$cmd" "sudo -e" - return - fi - - # Check for editor commands in the typed command and replace accordingly - case "$BUFFER" in - $editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudo -e" ;; - \$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudo -e" ;; - sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "$EDITOR" ;; - sudo\ *) __sudo-replace-buffer "sudo" "" ;; - *) LBUFFER="sudo $LBUFFER" ;; - esac - } always { - # Preserve beginning space - LBUFFER="${WHITESPACE}${LBUFFER}" - - # Redisplay edit buffer (compatibility with zsh-syntax-highlighting) - zle && zle redisplay # only run redisplay if zle is enabled - } -} - -zle -N sudo-command-line - -# Defined shortcut keys: [Esc] [Esc] -bindkey -M emacs '\e\e' sudo-command-line -bindkey -M vicmd '\e\e' sudo-command-line -bindkey -M viins '\e\e' sudo-command-line \ No newline at end of file diff --git a/share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh b/share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh deleted file mode 100644 index db44dea8..00000000 --- a/share/dotfiles/.config/zshrc/plugins/you-should-use.plugin.zsh +++ /dev/null @@ -1,279 +0,0 @@ -#!/bin/zsh - -export YSU_VERSION='1.7.3' - -if ! type "tput" > /dev/null; then - printf "WARNING: tput command not found on your PATH.\n" - printf "zsh-you-should-use will fallback to uncoloured messages\n" -else - NONE="$(tput sgr0)" - BOLD="$(tput bold)" - RED="$(tput setaf 1)" - YELLOW="$(tput setaf 3)" - PURPLE="$(tput setaf 5)" -fi - -function check_alias_usage() { - # Optional parameter that limits how far back history is checked - # I've chosen a large default value instead of bypassing tail because it's simpler - # TODO: this should probably be cleaned up - local limit="${1:-9000000000000000}" - local key - - declare -A usage - for key in "${(@k)aliases}"; do - usage[$key]=0 - done - - # TODO: - # Handle and (&&) + (&) - # others? watch, time etc... - - local current=0 - local total=$(wc -l < "$HISTFILE") - if [[ $total -gt $limit ]]; then - total=$limit - fi - - <"$HISTFILE" | tail "-$limit" | cut -d";" -f2 | while read line; do - local entry - for entry in ${(@s/|/)line}; do - # Remove leading whitespace - # TODO: This is extremely slow - entry="$(echo "$entry" | sed -e 's/^ *//')" - - # We only care about the first word because that's all aliases work with - # (this does not count global and git aliases) - local word=${entry[(w)1]} - if [[ -n ${usage[$word]} ]]; then - local prev=$usage[$word] - let "prev = prev + 1 " - usage[$word]=$prev - fi - done - - # print current progress - let "current = current + 1" - printf "[$current/$total]\r" - done - # Clear all previous line output - printf "\r\033[K" - - # Print ordered usage - for key in ${(k)usage}; do - echo "${usage[$key]}: $key='${aliases[$key]}'" - done | sort -rn -k1 -} - -# Writing to a buffer rather than directly to stdout/stderr allows us to decide -# if we want to write the reminder message before or after a command has been executed -function _write_ysu_buffer() { - _YSU_BUFFER+="$@" - - # Maintain historical behaviour by default - local position="${YSU_MESSAGE_POSITION:-before}" - if [[ "$position" = "before" ]]; then - _flush_ysu_buffer - elif [[ "$position" != "after" ]]; then - (>&2 printf "${RED}${BOLD}Unknown value for YSU_MESSAGE_POSITION '$position'. ") - (>&2 printf "Expected value 'before' or 'after'${NONE}\n") - _flush_ysu_buffer - fi -} - -function _flush_ysu_buffer() { - # It's important to pass $_YSU_BUFFER to printfs first argument - # because otherwise all escape codes will not printed correctly - (>&2 printf "$_YSU_BUFFER") - _YSU_BUFFER="" -} - -function ysu_message() { - local DEFAULT_MESSAGE_FORMAT="${BOLD}${YELLOW}\ -Found existing %alias_type for ${PURPLE}\"%command\"${YELLOW}. \ -You should use: ${PURPLE}\"%alias\"${NONE}" - - local alias_type_arg="${1}" - local command_arg="${2}" - local alias_arg="${3}" - - # Escape arguments which will be interpreted by printf incorrectly - # unfortunately there does not seem to be a nice way to put this into - # a function because returning the values requires to be done by printf/echo!! - command_arg="${command_arg//\%/%%}" - command_arg="${command_arg//\\/\\\\}" - - local MESSAGE="${YSU_MESSAGE_FORMAT:-"$DEFAULT_MESSAGE_FORMAT"}" - MESSAGE="${MESSAGE//\%alias_type/$alias_type_arg}" - MESSAGE="${MESSAGE//\%command/$command_arg}" - MESSAGE="${MESSAGE//\%alias/$alias_arg}" - - _write_ysu_buffer "$MESSAGE\n" -} - - -# Prevent command from running if hardcore mode enabled -function _check_ysu_hardcore() { - if [[ "$YSU_HARDCORE" = 1 ]]; then - _write_ysu_buffer "${BOLD}${RED}You Should Use hardcore mode enabled. Use your aliases!${NONE}\n" - kill -s INT $$ - fi -} - - -function _check_git_aliases() { - local typed="$1" - local expanded="$2" - - # sudo will use another user's profile and so aliases would not apply - if [[ "$typed" = "sudo "* ]]; then - return - fi - - if [[ "$typed" = "git "* ]]; then - local found=false - git config --get-regexp "^alias\..+$" | sort | while read key value; do - key="${key#alias.}" - - if [[ "$expanded" = "git $value" || "$expanded" = "git $value "* ]]; then - ysu_message "git alias" "$value" "git $key" - found=true - fi - done - - if $found; then - _check_ysu_hardcore - fi - fi -} - - -function _check_global_aliases() { - local typed="$1" - local expanded="$2" - - local found=false - local tokens - local key - local value - local entry - - # sudo will use another user's profile and so aliases would not apply - if [[ "$typed" = "sudo "* ]]; then - return - fi - - alias -g | sort | while read entry; do - tokens=("${(@s/=/)entry}") - key="${tokens[1]}" - # Need to remove leading and trailing ' if they exist - value="${(Q)tokens[2]}" - - # Skip ignored global aliases - if [[ ${YSU_IGNORED_GLOBAL_ALIASES[(r)$key]} == "$key" ]]; then - continue - fi - - if [[ "$typed" = *" $value "* || \ - "$typed" = *" $value" || \ - "$typed" = "$value "* || \ - "$typed" = "$value" ]]; then - ysu_message "global alias" "$value" "$key" - found=true - fi - done - - if $found; then - _check_ysu_hardcore - fi -} - - -function _check_aliases() { - local typed="$1" - local expanded="$2" - - local found_aliases - found_aliases=() - local best_match="" - local best_match_value="" - local key - local value - - # sudo will use another user's profile and so aliases would not apply - if [[ "$typed" = "sudo "* ]]; then - return - fi - - # Find alias matches - for key in "${(@k)aliases}"; do - value="${aliases[$key]}" - - # Skip ignored aliases - if [[ ${YSU_IGNORED_ALIASES[(r)$key]} == "$key" ]]; then - continue - fi - - if [[ "$typed" = "$value" || \ - "$typed" = "$value "* ]]; then - - # if the alias longer or the same length as its command - # we assume that it is there to cater for typos. - # If not, then the alias would not save any time - # for the user and so doesn't hold much value anyway - if [[ "${#value}" -gt "${#key}" ]]; then - - found_aliases+="$key" - - # Match aliases to longest portion of command - if [[ "${#value}" -gt "${#best_match_value}" ]]; then - best_match="$key" - best_match_value="$value" - # on equal length, choose the shortest alias - elif [[ "${#value}" -eq "${#best_match}" && ${#key} -lt "${#best_match}" ]]; then - best_match="$key" - best_match_value="$value" - fi - fi - fi - done - - # Print result matches based on current mode - if [[ "$YSU_MODE" = "ALL" ]]; then - for key in ${(@ok)found_aliases}; do - value="${aliases[$key]}" - ysu_message "alias" "$value" "$key" - done - - elif [[ (-z "$YSU_MODE" || "$YSU_MODE" = "BESTMATCH") && -n "$best_match" ]]; then - # make sure that the best matched alias has not already - # been typed by the user - value="${aliases[$best_match]}" - if [[ "$typed" = "$best_match" || "$typed" = "$best_match "* ]]; then - return - fi - ysu_message "alias" "$value" "$best_match" - fi - - if [[ -n "$found_aliases" ]]; then - _check_ysu_hardcore - fi -} - -function disable_you_should_use() { - add-zsh-hook -D preexec _check_aliases - add-zsh-hook -D preexec _check_global_aliases - add-zsh-hook -D preexec _check_git_aliases - add-zsh-hook -D precmd _flush_ysu_buffer -} - -function enable_you_should_use() { - disable_you_should_use # Delete any possible pre-existing hooks - add-zsh-hook preexec _check_aliases - add-zsh-hook preexec _check_global_aliases - add-zsh-hook preexec _check_git_aliases - add-zsh-hook precmd _flush_ysu_buffer -} - -autoload -Uz add-zsh-hook -enable_you_should_use From bb1fe803b601af523b5754d433483eb84dbd4387 Mon Sep 17 00:00:00 2001 From: 0blivi0nis <182329535+0blivi0nis@users.noreply.github.com> Date: Wed, 25 Sep 2024 20:09:39 -0700 Subject: [PATCH 4/8] Update shell.sh fixed gaps in script --- share/dotfiles/.config/ml4w/scripts/shell.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/share/dotfiles/.config/ml4w/scripts/shell.sh b/share/dotfiles/.config/ml4w/scripts/shell.sh index 259d9942..0e00b0e4 100755 --- a/share/dotfiles/.config/ml4w/scripts/shell.sh +++ b/share/dotfiles/.config/ml4w/scripts/shell.sh @@ -179,9 +179,6 @@ elif [[ $shell == "zsh" ]] ;then echo ":: zsh-plugin-you-should-use already installed" fi - - - # Install pkgfile if needed (for command not found) if ! command -v pkgfile &> /dev/null; then echo ":: Installing pkgfile" @@ -200,4 +197,4 @@ elif [[ $shell == "zsh" ]] ;then else echo ":: Changing shell canceled" exit -fi \ No newline at end of file +fi From d857526c842ea627a3a3c3a63098477287f1af5e Mon Sep 17 00:00:00 2001 From: Oblivionis <182329535+0blivi0nis@users.noreply.github.com> Date: Wed, 25 Sep 2024 20:24:56 -0700 Subject: [PATCH 5/8] Fixed ZSH 20-customization to source the plugins from the correct locations --- share/dotfiles/.config/zshrc/20-customization | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/share/dotfiles/.config/zshrc/20-customization b/share/dotfiles/.config/zshrc/20-customization index 0eddd3a9..4fe2f36b 100644 --- a/share/dotfiles/.config/zshrc/20-customization +++ b/share/dotfiles/.config/zshrc/20-customization @@ -7,16 +7,51 @@ POSH=agnoster # ----------------------------------------------------- # PLUGINS # ----------------------------------------------------- -source $HOME/.config/zshrc/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh -source $HOME/.config/zshrc/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh -source $HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh -source $HOME/.config/zshrc/plugins/zsh-completions/zsh-completions.plugin.zsh -source $HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh -source $HOME/.config/zshrc/plugins/command-not-found.plugin.zsh -source $HOME/.config/zshrc/plugins/dirhistory.plugin.zsh -source $HOME/.config/zshrc/plugins/extract.plugin.zsh -source $HOME/.config/zshrc/plugins/sudo.plugin.zsh -source $HOME/.config/zshrc/plugins/you-should-use.plugin.zsh +if [ -f "$HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/zsh-completions/zsh-completions.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/zsh-completions/zsh-completions.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/git.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/git.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/sudo.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/sudo.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/web-search.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/web-search.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/archlinux.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/archlinux.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/copyfile.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/copyfile.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/copybuffer.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/copybuffer.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/dirhistory.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/dirhistory.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/command-not-found.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/command-not-found.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/extract.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/extract.plugin.zsh" +fi +if [ -f "$HOME/.config/zshrc/plugins/you-should-use.plugin.zsh" ]; then + source "$HOME/.config/zshrc/plugins/you-should-use.plugin.zsh" +fi # ----------------------------------------------------- # Set-up FZF key bindings (CTRL R for fuzzy history finder) From e8354207465bc2e2e552080c2068313472b93910 Mon Sep 17 00:00:00 2001 From: Oblivionis <182329535+0blivi0nis@users.noreply.github.com> Date: Wed, 25 Sep 2024 20:37:52 -0700 Subject: [PATCH 6/8] Fixed ZSH 20-customization to include a better way of installing plugins --- share/dotfiles/.config/zshrc/20-customization | 135 +++++++++++++----- 1 file changed, 98 insertions(+), 37 deletions(-) diff --git a/share/dotfiles/.config/zshrc/20-customization b/share/dotfiles/.config/zshrc/20-customization index 4fe2f36b..05329262 100644 --- a/share/dotfiles/.config/zshrc/20-customization +++ b/share/dotfiles/.config/zshrc/20-customization @@ -4,71 +4,132 @@ POSH=agnoster +# ----------------------------------------------------- +# Set-up FZF key bindings (CTRL R for fuzzy history finder) +# ----------------------------------------------------- +source <(fzf --zsh) + +# zsh history +HISTFILE=~/.zsh_history +HISTSIZE=10000 +SAVEHIST=10000 +setopt appendhistory + +# ----------------------------------------------------- +# oh-my-posh promt +# ----------------------------------------------------- +# Custom Theme +eval "$(oh-my-posh init zsh --config $HOME/.config/ohmyposh/zen.toml)" + +# Shipped Theme +# eval "$(oh-my-posh init zsh --config /usr/share/oh-my-posh/themes/$POSH.omp.json)" + # ----------------------------------------------------- # PLUGINS # ----------------------------------------------------- -if [ -f "$HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh" ]; then + +# zsh-autosuggestions +if [ ! -d "$HOME/.config/zshrc/plugins/zsh-autosuggestions" ]; then + echo ":: Installing zsh-autosuggestions" + git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.config/zshrc/plugins/zsh-autosuggestions +else source "$HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh" ]; then - source "$HOME/.config/zshrc/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh" +# zsh-syntax-highlighting +if [ ! -d "$HOME/.config/zshrc/plugins/zsh-syntax-highlighting" ]; then + echo ":: Installing zsh-syntax-highlighting" + git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.config/zshrc/plugins/zsh-syntax-highlighting +else + source "$HOME/.config/zshrc/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh" ]; then +# fast-syntax-highlighting +if [ ! -d "$HOME/.config/zshrc/plugins/fast-syntax-highlighting" ]; then + echo ":: Installing fast-syntax-highlighting" + git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git $HOME/.config/zshrc/plugins/fast-syntax-highlighting +else source "$HOME/.config/zshrc/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/zsh-completions/zsh-completions.plugin.zsh" ]; then +# zsh-completions +if [ ! -d "$HOME/.config/zshrc/plugins/zsh-completions" ]; then + echo ":: Installing zsh-completions" + git clone https://github.com/zsh-users/zsh-completions.git $HOME/.config/zshrc/plugins/zsh-completions +else source "$HOME/.config/zshrc/plugins/zsh-completions/zsh-completions.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/git.plugin.zsh" ]; then +# zsh-plugin-git +if [ ! -f "$HOME/.config/zshrc/plugins/git.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-git" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/git/git.plugin.zsh -o $HOME/.config/zshrc/plugins/git.plugin.zsh +else source "$HOME/.config/zshrc/plugins/git.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/sudo.plugin.zsh" ]; then +# zsh-plugin-sudo +if [ ! -f "$HOME/.config/zshrc/plugins/sudo.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-sudo" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/sudo/sudo.plugin.zsh -o $HOME/.config/zshrc/plugins/sudo.plugin.zsh +else source "$HOME/.config/zshrc/plugins/sudo.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/web-search.plugin.zsh" ]; then +# zsh-plugin-web-search +if [ ! -f "$HOME/.config/zshrc/plugins/web-search.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-web-search" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/web-search/web-search.plugin.zsh -o $HOME/.config/zshrc/plugins/web-search.plugin.zsh +else source "$HOME/.config/zshrc/plugins/web-search.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/archlinux.plugin.zsh" ]; then +# zsh-plugin-archlinux +if [ ! -f "$HOME/.config/zshrc/plugins/archlinux.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-archlinux" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/archlinux/archlinux.plugin.zsh -o $HOME/.config/zshrc/plugins/archlinux.plugin.zsh +else source "$HOME/.config/zshrc/plugins/archlinux.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/copyfile.plugin.zsh" ]; then +# zsh-plugin-copyfile +if [ ! -f "$HOME/.config/zshrc/plugins/copyfile.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-copyfile" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/copyfile/copyfile.plugin.zsh -o $HOME/.config/zshrc/plugins/copyfile.plugin.zsh +else source "$HOME/.config/zshrc/plugins/copyfile.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/copybuffer.plugin.zsh" ]; then +# zsh-plugin-copybuffer +if [ ! -f "$HOME/.config/zshrc/plugins/copybuffer.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-copybuffer" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/copybuffer/copybuffer.plugin.zsh -o $HOME/.config/zshrc/plugins/copybuffer.plugin.zsh +else source "$HOME/.config/zshrc/plugins/copybuffer.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/dirhistory.plugin.zsh" ]; then +# zsh-plugin-dirhistory +if [ ! -f "$HOME/.config/zshrc/plugins/dirhistory.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-dirhistory" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/dirhistory/dirhistory.plugin.zsh -o $HOME/.config/zshrc/plugins/dirhistory.plugin.zsh +else source "$HOME/.config/zshrc/plugins/dirhistory.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh" ]; then +# zsh-plugin-colored-man-pages +if [ ! -f "$HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-colored-man-pages" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/colored-man-pages/colored-man-pages.plugin.zsh -o $HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh +else source "$HOME/.config/zshrc/plugins/colored-man-pages.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/command-not-found.plugin.zsh" ]; then +# zsh-plugin-command-not-found +if [ ! -f "$HOME/.config/zshrc/plugins/command-not-found.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-command-not-found" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/command-not-found/command-not-found.plugin.zsh -o $HOME/.config/zshrc/plugins/command-not-found.plugin.zsh +else source "$HOME/.config/zshrc/plugins/command-not-found.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/extract.plugin.zsh" ]; then +# zsh-plugin-extract +if [ ! -f "$HOME/.config/zshrc/plugins/extract.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-extract" + curl https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/refs/heads/master/plugins/extract/extract.plugin.zsh -o $HOME/.config/zshrc/plugins/extract.plugin.zsh +else source "$HOME/.config/zshrc/plugins/extract.plugin.zsh" fi -if [ -f "$HOME/.config/zshrc/plugins/you-should-use.plugin.zsh" ]; then +# zsh-plugin-you-should-use +if [ ! -f "$HOME/.config/zshrc/plugins/you-should-use.plugin.zsh" ]; then + echo ":: Installing zsh-plugin-you-should-use" + curl https://raw.githubusercontent.com/MichaelAquilina/zsh-you-should-use/refs/heads/master/you-should-use.plugin.zsh -o $HOME/.config/zshrc/plugins/you-should-use.plugin.zsh +else source "$HOME/.config/zshrc/plugins/you-should-use.plugin.zsh" -fi - -# ----------------------------------------------------- -# Set-up FZF key bindings (CTRL R for fuzzy history finder) -# ----------------------------------------------------- -source <(fzf --zsh) - -# zsh history -HISTFILE=~/.zsh_history -HISTSIZE=10000 -SAVEHIST=10000 -setopt appendhistory - -# ----------------------------------------------------- -# oh-my-posh promt -# ----------------------------------------------------- -# Custom Theme -eval "$(oh-my-posh init zsh --config $HOME/.config/ohmyposh/zen.toml)" - -# Shipped Theme -# eval "$(oh-my-posh init zsh --config /usr/share/oh-my-posh/themes/$POSH.omp.json)" +fi \ No newline at end of file From 6760cf5c8a648dff68ccb26b9d1544dffb9fa1cd Mon Sep 17 00:00:00 2001 From: 0blivi0nis Date: Sat, 28 Sep 2024 18:19:56 -0700 Subject: [PATCH 7/8] feat(265): Custom AUR Helper Instead of checking for installed AUR helpers liek yay and paru and then deciding what to do, this script initially asks the user what their preferred AUR helper is, it then checks if the chosen helper is installed. If not, the script then installs the chosen AUR helper and cleans up after it self at then end. --- lib/install/packages/aur.sh | 74 +++++++++---------------------------- 1 file changed, 18 insertions(+), 56 deletions(-) diff --git a/lib/install/packages/aur.sh b/lib/install/packages/aur.sh index 0eb162a0..7f50f700 100644 --- a/lib/install/packages/aur.sh +++ b/lib/install/packages/aur.sh @@ -1,68 +1,31 @@ # ------------------------------------------------------ -# Check if yay is installed +# Select AUR Helper # ------------------------------------------------------ -yay_installed="false" -paru_installed="false" aur_helper="" -_installYay() { - _installPackagesPacman "base-devel" - SCRIPT=$(realpath "$0") - temp_path=$(dirname "$SCRIPT") - git clone https://aur.archlinux.org/yay.git ~/yay - cd ~/yay - makepkg -si - cd $temp_path - echo ":: yay has been installed successfully." -} - -_installParu() { - _installPackagesPacman "base-devel" - SCRIPT=$(realpath "$0") - temp_path=$(dirname "$SCRIPT") - git clone https://aur.archlinux.org/paru.git ~/paru - cd ~/paru - makepkg -si - cd $temp_path - echo ":: paru has been installed successfully." -} - _selectAURHelper() { echo ":: Please select your preferred AUR Helper" echo - aur_helper=$(gum choose "yay" "paru") + aur_helper=$(gum choose "yay" "paru" "pikaur" "trizen" "aurman" "pacaur" "pakku") if [ -z $aur_helper ] ;then _selectAURHelper fi -} - -_checkAURHelper() { - if [[ $(_checkCommandExists "yay") == "0" ]];then - echo ":: yay is installed" - yay_installed="true" - fi - if [[ $(_checkCommandExists "paru") == "0" ]];then - echo ":: paru is installed" - paru_installed="true" - fi - if [[ $yay_installed == "true" ]] && [[ $paru_installed == "false" ]] ;then - echo ":: Using AUR Helper yay" - aur_helper="yay" - elif [[ $yay_installed == "false" ]] && [[ $paru_installed == "true" ]] ;then - echo ":: Using AUR Helper paru" - aur_helper="paru" - elif [[ $yay_installed == "false" ]] && [[ $paru_installed == "false" ]] ;then - if [[ $(_check_update) == "false" ]] ;then - _selectAURHelper - if [[ $aur_helper == "yay" ]] ;then - _installYay - else - _installParu - fi - fi + if command -v "$aur_helper" &> /dev/null; then + echo ":: $aur_helper is already installed." + return 0 else - _selectAURHelper + echo ":: Installing $aur_helper..." + cd $HOME + if [ -d "$HOME/$aur_helper" ]; then + rm -rf "$HOME/$aur_helper" + fi + git clone "https://aur.archlinux.org/$aur_helper.git" ~/$aur_helper || { echo ":: Failed to clone $aur_helper."; return 1; } + cd $HOME/"$aur_helper" || { echo ":: Failed to change directory to $aur_helper."; return 1; } + makepkg -si --noconfirm || { echo ":: Installation of $aur_helper failed."; return 1; } + cd $HOME + rm -rf "$aur_helper" + echo ":: $aur_helper installed successfully." fi } @@ -70,6 +33,5 @@ if [[ $(_check_update) == "false" ]] ;then echo -e "${GREEN}" figlet -f smslant "AUR Helper" echo -e "${NONE}" -fi -_checkAURHelper - + _selectAURHelper +fi \ No newline at end of file From b7a9843cd2228f8be553d2090b976ee1437124c2 Mon Sep 17 00:00:00 2001 From: 0blivi0nis Date: Sun, 29 Sep 2024 00:20:36 -0700 Subject: [PATCH 8/8] fix: Removed Starship and zsh-completions, added nautilus. --- share/packages/general.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/share/packages/general.sh b/share/packages/general.sh index 89c6ef07..5f8f2f44 100644 --- a/share/packages/general.sh +++ b/share/packages/general.sh @@ -53,6 +53,7 @@ packagesPacman=( "fzf" "htop" "rsync" + "nautilus" ); packagesAUR=(