From 5b6287673093669efaab10df8822f7a40bac5ac3 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Thu, 1 Jan 2026 03:11:11 +0100 Subject: [PATCH] better profile handling --- config/shell/.bash_profile | 92 ++++++++++++++++++---- config/shell/.config/fish/post.d/sshs.fish | 2 +- config/shell/.config/fish/prev.d/env.fish | 20 +++-- 3 files changed, 92 insertions(+), 22 deletions(-) diff --git a/config/shell/.bash_profile b/config/shell/.bash_profile index c44731e..8d5b7ec 100644 --- a/config/shell/.bash_profile +++ b/config/shell/.bash_profile @@ -1,19 +1,81 @@ -[ -d "$HOME/.local/bin" ] && export PATH="$HOME/.local/bin:$PATH" -[ -d "$HOME/.local/scripts" ] && export PATH="$HOME/.local/scripts:$PATH" -[ -d "$HOME/.cargo/bin" ] && export PATH="$HOME/.cargo/bin:$PATH" +#!/bin/bash + +# From archlinux's /etc/profile +append_path () { + case ":$PATH:" in + *:"$1":*) + ;; + *) + PATH="${PATH:+$PATH:}$1" + esac +} +prepend_path () { + case ":$PATH:" in + *:"$1":*) + ;; + *) + PATH="$1${PATH:+:$PATH}" + esac +} + +# Better than nothing +export XDG_CONFIG_HOME="$HOME/.config" +export XDG_DATA_HOME="$HOME/.local/share" +export XDG_STATE_HOME="$HOME/.local/state" +export XDG_CACHE_HOME="$HOME/.cache" + +# Better than nothing +if [[ -z "$LANG" ]]; then + export LANG="en_US.UTF-8" + export LC_ALL="en_US.UTF-8" +fi + +# Paths [ -f "$HOME/.cargo/env" ] && source "$HOME/.cargo/env" -[ -d "$HOME/go/bin" ] && export PATH="$HOME/go/bin:$PATH" +[ -d "$HOME/go/bin" ] && prepend_path "$HOME/go/bin" +[ -d "$HOME/.local/bin" ] && prepend_path "$HOME/.local/bin" +[ -d "$HOME/.local/scripts" ] && prepend_path "$HOME/.local/scripts" +export PATH -[ -x "$HOME/.local/scripts/ssh-init" ] && eval "$(ssh-init)" >/dev/null 2>&1 - -command -v nvim >/dev/null 2>&1 && { - export EDITOR=nvim - export VISUAL=nvim -} - -command -v f >/dev/null 2>&1 || { - alias f="exec fish" -} +# SSH with cross-session ssh-agent +if [ -x "$HOME/.local/scripts/ssh-init" ]; then + eval "$($HOME/.local/scripts/ssh-init 2>/dev/null)" >/dev/null 2>&1 +fi +# .profile is not included in the repo [ -f "$HOME/.profile" ] && . "$HOME/.profile" -[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" + +# Triggered when SSH into the machine +if [[ $- == *i* ]]; then + # Set EDITOR and VISUAL, mainly for sudoedit + for app in helix nvim vim vi nano; do + if command -v "$app" >/dev/null 2>&1; then + EDITOR="$app" + VISUAL="$app" + break + fi + done + export EDITOR VISUAL + + # For gpg + GPG_TTY=$(tty) + export GPG_TTY + + # Shortcut alias for launching fish + command -v f >/dev/null 2>&1 || { + alias f="exec fish" + } + # Better do this manually since the automatic approach is kinda buggy. + # Add this to .bashrc to enable it anyway: + # + # if [[ $(ps --no-header --pid=$PPID --format=comm) != "fish" && -z ${BASH_EXECUTION_STRING} && ${SHLVL} == 1 ]]; then + # shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION='' + # exec fish $LOGIN_OPTION + # fi + + # .bashrc is not included in the repo + [ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc" +fi + +unset append_path +unset prepend_path \ No newline at end of file diff --git a/config/shell/.config/fish/post.d/sshs.fish b/config/shell/.config/fish/post.d/sshs.fish index f02fa45..89dced3 100644 --- a/config/shell/.config/fish/post.d/sshs.fish +++ b/config/shell/.config/fish/post.d/sshs.fish @@ -3,7 +3,7 @@ if type -q ssh bass $(ssh-init) > /dev/null 2>&1 - # avoiding entering passphrase every time + # avoid entering passphrase every time function sshs # test if keys are added to ssh-agent if not ssh-add -l > /dev/null 2>&1 diff --git a/config/shell/.config/fish/prev.d/env.fish b/config/shell/.config/fish/prev.d/env.fish index e6a5428..8e53ed7 100644 --- a/config/shell/.config/fish/prev.d/env.fish +++ b/config/shell/.config/fish/prev.d/env.fish @@ -1,8 +1,8 @@ # PATH +fish_add_path $HOME/go/bin +fish_add_path $HOME/.cargo/bin fish_add_path $HOME/.local/scripts fish_add_path $HOME/.local/bin -fish_add_path $HOME/.cargo/bin -fish_add_path $HOME/go/bin # man if type -q bat @@ -10,10 +10,18 @@ if type -q bat set -x -g MANROFFOPT -c end -# nvim -if type -q nvim - set -x -g EDITOR nvim - set -x -g VISUAL nvim +# Editor +for app in helix nvim vim vi nano + if type -q $app + set -x -g EDITOR $app + set -x -g VISUAL $app + break + end +end + +# Create shortcut alias for helix +if type -q helix; and not type -q hx + alias hx helix end # gpg