update shell config

Amolith created

Change summary

dot_config/zsh/private_dot_zimrc      |  11 ++
dot_config/zsh/private_dot_zshrc.tmpl | 112 ++++++++++++++++++++--------
2 files changed, 88 insertions(+), 35 deletions(-)

Detailed changes

dot_config/zsh/private_dot_zimrc 🔗

@@ -22,9 +22,6 @@ zmodule git-info
 
 # Additional completion definitions for Zsh.
 zmodule zsh-users/zsh-completions
-# Enables and configures smart and extensive tab completion.
-# completion must be sourced after zsh-users/zsh-completions
-zmodule completion
 # Fish-like autosuggestions for Zsh.
 zmodule zsh-users/zsh-autosuggestions
 # Fish-like syntax highlighting for Zsh.
@@ -41,3 +38,11 @@ zmodule fzf
 zmodule prompt-pwd
 zmodule s1ck94
 zmodule ssh
+zmodule joke/zim-starship
+zmodule joke/zim-chezmoi
+
+fpath=($XDG_CONFIG_HOME/zsh/completions $fpath)
+
+# Enables and configures smart and extensive tab completion.
+# completion must be sourced after zsh-users/zsh-completions
+zmodule completion

dot_config/zsh/private_dot_zshrc.tmpl 🔗

@@ -63,6 +63,8 @@ export GHCUP_USE_XDG_DIRS="ishouldjustbeabletoexportthisnotsetit"
 alias wget=wget --hsts-file="$XDG_DATA_HOME/wget-hsts"
 alias svn="svn --config-dir $XDG_CONFIG_HOME/subversion"
 
+fpath=($XDG_CONFIG_HOME/zsh/completions $fpath)
+
 # ------------------
 # Initialize modules
 # ------------------
@@ -149,20 +151,16 @@ export RAD_PASSWORD='{{ onepasswordRead "op://Private/2ujzijel6ni3np2uj5k5syptzm
 
 export JIRA_API_TOKEN='{{ onepasswordRead "op://Private/Atlassian/jira key" }}'
 
+# LLM Crap
+export TOGETHER_API_KEY='{{ onepasswordRead "op://Private/pjn4bg6prgvta2ncdory42zrta/llm" }}'
+export OPENROUTER_API_KEY='{{ onepasswordRead "op://Private/OpenRouter/shell" }}'
+export OPENAI_API_BASE='https://api.together.xyz/v1'
+export OPENAI_API_KEY=$TOGETHER_API_KEY
+
 #HYPHEN_INSENSITIVE="true"
 # Uncomment the following line if pasting URLs and other text is messed up.
 # DISABLE_MAGIC_FUNCTIONS=true
 
-# Integrate z - jump around
-source /usr/share/z/z.sh
-
-# Integrate FZF
-source /usr/share/fzf/key-bindings.zsh
-source /usr/share/fzf/completion.zsh
-
-# Completions for git extras
-source /usr/share/doc/git-extras/git-extras-completion.zsh
-
 # Ranger conf
 export RANGER_LOAD_DEFAULT_RC=false
 
@@ -172,7 +170,6 @@ alias ts="tailscale"
 alias tmateqr='tmate show-messages | tail -n 1 | qrencode -o - -t ANSIUTF8'
 alias info="info --vi-keys"
 alias datetime="date +%Y-%m-%d_%H%M%S_%Z"
-alias e="devour eval $EDITOR"
 alias u="linx-client"
 alias clip="xclip -selection clipboard"
 alias tmp="cd $(mktemp -d) && export TEMP=$(pwd)"
@@ -204,24 +201,87 @@ function gi() {
 	curl -sLw https://www.toptal.com/developers/gitignore/api/$@ ;
 }
 
+
 sshedit() {
-	emulate -L zsh
-    setopt err_exit no_unset pipe_fail
+    emulate -L zsh
+    setopt pipefail
+
+    if [[ $# -lt 2 ]]; then
+        echo "Usage: sshedit remote_host remote_file" >&2
+        return 1
+    fi
 
     local tmpdir=$(mktemp -d)
     chmod 700 "$tmpdir"
-    pushd "$tmpdir" > /dev/null
+
+    # Define cleanup function
+    function cleanup() {
+        [[ $PWD == $tmpdir ]] && popd >/dev/null 2>&1
+        [[ -d "$tmpdir" ]] && rm -rf "$tmpdir"
+    }
+    # Set trap but don't use EXIT which might cause terminal closure
+    trap cleanup INT TERM HUP
+
+    pushd "$tmpdir" > /dev/null || { echo "Failed to enter temp directory"; return 1; }
+
     local remote_host="$1"
     local remote_file="$2"
     local local_file="${remote_file:t}"  # ZSH way to get basename
 
-    rsync -az "${remote_host}:${remote_file}" "$local_file"
-    eval "$EDITOR $local_file"
-    rsync -az "$local_file" "${remote_host}:${remote_file}"
-    popd > /dev/null
-    rm -rf "$tmpdir"
+    # Check ssh connection
+    if ! ssh -q -o BatchMode=yes -o ConnectTimeout=5 "$remote_host" true; then
+        echo "Error: Cannot connect to $remote_host" >&2
+        cleanup
+        return 1
+    fi
+
+    if ! ssh "$remote_host" "test -f '$remote_file'"; then
+        echo -n "Remote file doesn't exist. Create it? [y/N] " >&2
+        read -q response || { echo "\nAborting" >&2; return 1 }
+        echo
+        ssh "$remote_host" "touch '$remote_file'" || {
+            echo "Failed to create remote file" >&2
+            return 1
+        }
+    fi
+
+    # Download file
+    if ! rsync -az "${remote_host}:${remote_file}" "$local_file"; then
+        echo "Error: Failed to download the remote file" >&2
+        cleanup
+        return 1
+    fi
+
+    local before_checksum=$(sha256sum "$local_file" 2>/dev/null | awk '{print $1}')
+
+    eval "${EDITOR:-vim}" "$local_file"
+    local edit_status=$?
+
+    if [[ $edit_status -ne 0 ]]; then
+        echo "Editor exited with status $edit_status" >&2
+        cleanup
+        return $edit_status
+    fi
+
+    local after_checksum=$(sha256sum "$local_file" 2>/dev/null | awk '{print $1}')
+
+    if [[ "$before_checksum" != "$after_checksum" ]]; then
+        if ! rsync -az "$local_file" "${remote_host}:${remote_file}"; then
+            echo "Error: Failed to upload edited file" >&2
+            cleanup
+            return 1
+        fi
+        echo "File successfully updated on $remote_host" >&2
+    else
+        echo "No changes made to file" >&2
+    fi
+
+    cleanup
+    trap - INT TERM HUP
+    return 0
 }
 
+
 # Navi integration
 _call_navi() {
   local selected
@@ -242,15 +302,8 @@ zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p
 zstyle :compinstall filename '/home/amolith/.config/zsh/.zshrc'
 
 # Additional completions
-source $XDG_CONFIG_HOME/zsh/completions/charm.zsh
-source $XDG_CONFIG_HOME/zsh/completions/starship.zsh
-source $XDG_CONFIG_HOME/zsh/completions/antidot.zsh
-source $XDG_CONFIG_HOME/zsh/completions/klog.zsh
-source $XDG_CONFIG_HOME/zsh/completions/chezmoi.zsh
-source $XDG_CONFIG_HOME/zsh/completions/himalaya.zsh
 eval "$(op completion zsh)"; compdef _op op
-
-eval "$(starship init zsh)"
+source /usr/share/z/z.sh
 
 precmd_functions=(zvm_init "${(@)precmd_functions:#zvm_init}")
 precmd_functions+=(set-long-prompt)
@@ -309,8 +362,3 @@ zvm_after_init_commands+=('
 export HISTFILE="$XDG_STATE_HOME"/zsh/history
 export HISTSIZE=1000000
 export SAVEHIST=1000000
-
-autoload -Uz compinit && compinit
-autoload -U +X bashcompinit && bashcompinit
-
-compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"