diff --git a/arch-user/bin/wsudo b/arch-user/bin/wsudo index dde7458..4bf1df8 100755 --- a/arch-user/bin/wsudo +++ b/arch-user/bin/wsudo @@ -12,7 +12,6 @@ parse() { local expanded=() for arg in "$@"; do if [[ $arg =~ ^-[a-zA-Z]{2,}$ ]]; then - # This is a combined flag like -iu local chars="${arg:1}" for ((j=0; j<${#chars}; j++)); do expanded+=("-${chars:$j:1}") @@ -34,36 +33,26 @@ parse() { if [[ $i -lt $arg_count ]]; then sudo_user="${args[$i]}" fi - ((i++)) - ;; + ((i++));; -i|--login) sudo_login_shell=true - ((i++)) - ;; + ((i++));; -s|--shell) - ((i++)) - ;; + ((i++));; --) ((i++)) sudo_command="${args[*]:$i}" - break - ;; + break;; -*) - # Unknown flag, skip it - ((i++)) - ;; + ((i++));; su) ((i++)) local su_user="" local su_args=() - - # Collect all remaining args for su processing while [[ $i -lt $arg_count ]]; do su_args+=("${args[$i]}") ((i++)) done - - # Expand combined flags in su arguments local su_expanded=() for arg in "${su_args[@]}"; do if [[ $arg =~ ^-[a-zA-Z]{2,}$ ]]; then @@ -75,58 +64,47 @@ parse() { su_expanded+=("$arg") fi done - - # Process expanded su arguments local k=0 local su_count=${#su_expanded[@]} while [[ $k -lt $su_count ]]; do case "${su_expanded[$k]}" in -|-l|--login) sudo_login_shell=true - ((k++)) - ;; + ((k++));; -c|--command) ((k++)) if [[ $k -lt $su_count ]]; then sudo_command="${su_expanded[$k]}" ((k++)) - fi - ;; + fi;; --session-command=*) sudo_command="${su_expanded[$k]#*=}" - ((k++)) - ;; + ((k++));; -m|-p|--preserve-environment) - ((k++)) - ;; + ((k++));; -s|--shell) ((k++)) if [[ $k -lt $su_count && "${su_expanded[$k]}" != -* ]]; then ((k++)) - fi - ;; + fi;; -*) - ((k++)) - ;; + ((k++));; *) if [[ -z "$su_user" ]]; then su_user="${su_expanded[$k]}" ((k++)) else ((k++)) - fi - ;; + fi;; esac done if [[ -n "$su_user" ]]; then sudo_user="$su_user" fi - break - ;; + break;; *) sudo_command="${args[*]:$i}" - break - ;; + break;; esac done } diff --git a/arch-user/config/workspace-compat/bashrc b/arch-user/config/workspace-compat/bashrc new file mode 100644 index 0000000..bed4550 --- /dev/null +++ b/arch-user/config/workspace-compat/bashrc @@ -0,0 +1,11 @@ +[ -f ~/.bashrc ] && . ~/.bashrc +stty intr ^K +alias ssh='wssh' +alias sudo='wsudo' +su() { + if [ "$1" = "-" ]; then + shift && wsudo - -u "$@" + else + wsudo -u "$@" + fi +} diff --git a/arch-user/config/workspace-compat/profile.tmpl b/arch-user/config/workspace-compat/profile.tmpl index 5a97cb1..45d02e9 100644 --- a/arch-user/config/workspace-compat/profile.tmpl +++ b/arch-user/config/workspace-compat/profile.tmpl @@ -12,18 +12,7 @@ export SHELL=/bin/bash export PATH="$WSCOMPAT_DIR:$PATH" cat << 'WSCOMPAT_EOF_04tcIQE7' > "$WSCOMPAT_DIR/bashrc" - -[ -f ~/.bashrc ] && . ~/.bashrc -stty intr ^K -alias ssh='wssh' -alias sudo='wsudo' -su() { - if [ "$1" = "-" ]; then - shift && wsudo - -u "$@" - else - wsudo -u "$@" - fi -} +{{ tmpl.Inline (file.Read "config/workspace-compat/bashrc") . }} WSCOMPAT_EOF_04tcIQE7 export VIMINIT="source $WSCOMPAT_DIR/vimrc" diff --git a/arch-user/install.sh b/arch-user/install.sh index bf77f38..3f0195c 100755 --- a/arch-user/install.sh +++ b/arch-user/install.sh @@ -71,7 +71,8 @@ gomplate --input-dir config \ --plugin jq=/bin/jq \ -c theme=config/theme.json \ -c user="file:///$HOME/.config/workspace.conf?type=application/x-env" \ - --exclude /workspace.conf --exclude /workspace-compat/profile.tmpl + --exclude /workspace.conf \ + --exclude /workspace-compat/* --exclude !/workspace-compat/env.sh ln -sf ~/.config/bash/bashrc ~/.bashrc ln -sf ~/.config/profile ~/.profile