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=() local expanded=()
for arg in "$@"; do for arg in "$@"; do
if [[ $arg =~ ^-[a-zA-Z]{2,}$ ]]; then if [[ $arg =~ ^-[a-zA-Z]{2,}$ ]]; then
# This is a combined flag like -iu
local chars="${arg:1}" local chars="${arg:1}"
for ((j=0; j<${#chars}; j++)); do for ((j=0; j<${#chars}; j++)); do
expanded+=("-${chars:$j:1}") expanded+=("-${chars:$j:1}")
@ -34,36 +33,26 @@ parse() {
if [[ $i -lt $arg_count ]]; then if [[ $i -lt $arg_count ]]; then
sudo_user="${args[$i]}" sudo_user="${args[$i]}"
fi fi
((i++)) ((i++));;
;;
-i|--login) -i|--login)
sudo_login_shell=true sudo_login_shell=true
((i++)) ((i++));;
;;
-s|--shell) -s|--shell)
((i++)) ((i++));;
;;
--) --)
((i++)) ((i++))
sudo_command="${args[*]:$i}" sudo_command="${args[*]:$i}"
break break;;
;;
-*) -*)
# Unknown flag, skip it ((i++));;
((i++))
;;
su) su)
((i++)) ((i++))
local su_user="" local su_user=""
local su_args=() local su_args=()
# Collect all remaining args for su processing
while [[ $i -lt $arg_count ]]; do while [[ $i -lt $arg_count ]]; do
su_args+=("${args[$i]}") su_args+=("${args[$i]}")
((i++)) ((i++))
done done
# Expand combined flags in su arguments
local su_expanded=() local su_expanded=()
for arg in "${su_args[@]}"; do for arg in "${su_args[@]}"; do
if [[ $arg =~ ^-[a-zA-Z]{2,}$ ]]; then if [[ $arg =~ ^-[a-zA-Z]{2,}$ ]]; then
@ -75,58 +64,47 @@ parse() {
su_expanded+=("$arg") su_expanded+=("$arg")
fi fi
done done
# Process expanded su arguments
local k=0 local k=0
local su_count=${#su_expanded[@]} local su_count=${#su_expanded[@]}
while [[ $k -lt $su_count ]]; do while [[ $k -lt $su_count ]]; do
case "${su_expanded[$k]}" in case "${su_expanded[$k]}" in
-|-l|--login) -|-l|--login)
sudo_login_shell=true sudo_login_shell=true
((k++)) ((k++));;
;;
-c|--command) -c|--command)
((k++)) ((k++))
if [[ $k -lt $su_count ]]; then if [[ $k -lt $su_count ]]; then
sudo_command="${su_expanded[$k]}" sudo_command="${su_expanded[$k]}"
((k++)) ((k++))
fi fi;;
;;
--session-command=*) --session-command=*)
sudo_command="${su_expanded[$k]#*=}" sudo_command="${su_expanded[$k]#*=}"
((k++)) ((k++));;
;;
-m|-p|--preserve-environment) -m|-p|--preserve-environment)
((k++)) ((k++));;
;;
-s|--shell) -s|--shell)
((k++)) ((k++))
if [[ $k -lt $su_count && "${su_expanded[$k]}" != -* ]]; then if [[ $k -lt $su_count && "${su_expanded[$k]}" != -* ]]; then
((k++)) ((k++))
fi fi;;
;;
-*) -*)
((k++)) ((k++));;
;;
*) *)
if [[ -z "$su_user" ]]; then if [[ -z "$su_user" ]]; then
su_user="${su_expanded[$k]}" su_user="${su_expanded[$k]}"
((k++)) ((k++))
else else
((k++)) ((k++))
fi fi;;
;;
esac esac
done done
if [[ -n "$su_user" ]]; then if [[ -n "$su_user" ]]; then
sudo_user="$su_user" sudo_user="$su_user"
fi fi
break break;;
;;
*) *)
sudo_command="${args[*]:$i}" sudo_command="${args[*]:$i}"
break break;;
;;
esac esac
done 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" export PATH="$WSCOMPAT_DIR:$PATH"
cat << 'WSCOMPAT_EOF_04tcIQE7' > "$WSCOMPAT_DIR/bashrc" cat << 'WSCOMPAT_EOF_04tcIQE7' > "$WSCOMPAT_DIR/bashrc"
{{ tmpl.Inline (file.Read "config/workspace-compat/bashrc") . }}
[ -f ~/.bashrc ] && . ~/.bashrc
stty intr ^K
alias ssh='wssh'
alias sudo='wsudo'
su() {
if [ "$1" = "-" ]; then
shift && wsudo - -u "$@"
else
wsudo -u "$@"
fi
}
WSCOMPAT_EOF_04tcIQE7 WSCOMPAT_EOF_04tcIQE7
export VIMINIT="source $WSCOMPAT_DIR/vimrc" export VIMINIT="source $WSCOMPAT_DIR/vimrc"

View File

@ -71,7 +71,8 @@ gomplate --input-dir config \
--plugin jq=/bin/jq \ --plugin jq=/bin/jq \
-c theme=config/theme.json \ -c theme=config/theme.json \
-c user="file:///$HOME/.config/workspace.conf?type=application/x-env" \ -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/bash/bashrc ~/.bashrc
ln -sf ~/.config/profile ~/.profile ln -sf ~/.config/profile ~/.profile