minor structural improvements

This commit is contained in:
Yuri Zamyatin 2025-10-12 18:54:08 +00:00
parent ee1c79f088
commit 38d44f03d3
No known key found for this signature in database
GPG Key ID: 4009A4CD0333B579
4 changed files with 28 additions and 50 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -12,19 +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"

View File

@ -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