From cb44890c3de710fd53353f944a501356519250cf Mon Sep 17 00:00:00 2001 From: agryphus Date: Thu, 9 Nov 2023 13:35:16 -0500 Subject: [PATCH] Added shell menu hotkey to zsh --- .config/zsh/.zshrc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 3aafb86..5cd6395 100755 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -80,9 +80,21 @@ function br { fi } +function nix_shell_menu { + shell_dir="$HOME/shells" + shells=$(ls "$shell_dir") + selection=$(echo "$shells" | rofi -dmenu) + nix-shell "$shell_dir/$selection" --run " + export NIX_SHELL_NAME=${selection%.*}; + $([ "$1" = "fhs" ] && echo "fhs-run ")$SHELL + " +} + ## KEYBINDS ## bindkey -s '^e' 'lfcd\n' +bindkey -s '^n' 'nix_shell_menu\n' +bindkey -s '^[n' 'nix_shell_menu fhs\n' # Enable completion features autoload -Uz compinit @@ -116,7 +128,8 @@ function precmd { err="$?" curr_time="%*" dir='%(4~|.../%3~|%~)' # 3 deep, or truncation - PROMPT="${C_PROMPT}[$USERNAME@$(sed 1q /etc/hostname)${C_DIR}:${dir}${C_PROMPT}]" + hostname="$([ -f /etc/hostname ] && echo "@$(sed 1q /etc/hostname)")" + PROMPT="${C_PROMPT}[$USERNAME$hostname${C_DIR}:${dir}${C_PROMPT}]" extra="$(parse_conda)$(parse_git)" if [ ! -z "$extra" ]; then PROMPT+=$'\n'"$extra" @@ -171,12 +184,21 @@ function parse_git() { function parse_conda() { env=$CONDA_DEFAULT_ENV - if [ -z "$env" ]; then + if [ ! -z "$env" ]; then + output="$env" + fi + + nix_shell=$NIX_SHELL_NAME + if [ ! -z "$nix_shell" ]; then + output="$nix_shell" + fi + + if [ -z "$output" ]; then echo "" return fi - echo "${C_CONDA}[$env]" + echo "${C_CONDA}[$output]" } # Config for zsh-syntax-highlighting