configs
This commit is contained in:
parent
0ed437b0ea
commit
06660b992f
@ -7,6 +7,26 @@ parse() {
|
|||||||
local args=("$@")
|
local args=("$@")
|
||||||
local i=0
|
local i=0
|
||||||
local arg_count=${#args[@]}
|
local arg_count=${#args[@]}
|
||||||
|
|
||||||
|
expand_flags() {
|
||||||
|
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}")
|
||||||
|
done
|
||||||
|
else
|
||||||
|
expanded+=("$arg")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
args=("${expanded[@]}")
|
||||||
|
arg_count=${#args[@]}
|
||||||
|
}
|
||||||
|
|
||||||
|
expand_flags "$@"
|
||||||
|
|
||||||
while [[ $i -lt $arg_count ]]; do
|
while [[ $i -lt $arg_count ]]; do
|
||||||
case "${args[$i]}" in
|
case "${args[$i]}" in
|
||||||
-u|--user)
|
-u|--user)
|
||||||
@ -29,46 +49,71 @@ parse() {
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
|
# Unknown flag, skip it
|
||||||
((i++))
|
((i++))
|
||||||
;;
|
;;
|
||||||
su)
|
su)
|
||||||
((i++))
|
((i++))
|
||||||
local su_user=""
|
local su_user=""
|
||||||
|
local su_args=()
|
||||||
|
|
||||||
|
# Collect all remaining args for su processing
|
||||||
while [[ $i -lt $arg_count ]]; do
|
while [[ $i -lt $arg_count ]]; do
|
||||||
case "${args[$i]}" in
|
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
|
||||||
|
local chars="${arg:1}"
|
||||||
|
for ((j=0; j<${#chars}; j++)); do
|
||||||
|
su_expanded+=("-${chars:$j:1}")
|
||||||
|
done
|
||||||
|
else
|
||||||
|
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)
|
-|-l|--login)
|
||||||
sudo_login_shell=true
|
sudo_login_shell=true
|
||||||
((i++))
|
((k++))
|
||||||
;;
|
;;
|
||||||
-c|--command)
|
-c|--command)
|
||||||
((i++))
|
((k++))
|
||||||
if [[ $i -lt $arg_count ]]; then
|
if [[ $k -lt $su_count ]]; then
|
||||||
sudo_command="${args[$i]}"
|
sudo_command="${su_expanded[$k]}"
|
||||||
((i++))
|
((k++))
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
--session-command=*)
|
--session-command=*)
|
||||||
sudo_command="${args[$i]#*=}"
|
sudo_command="${su_expanded[$k]#*=}"
|
||||||
((i++))
|
((k++))
|
||||||
;;
|
;;
|
||||||
-m|-p|--preserve-environment)
|
-m|-p|--preserve-environment)
|
||||||
((i++))
|
((k++))
|
||||||
;;
|
;;
|
||||||
-s|--shell)
|
-s|--shell)
|
||||||
((i++))
|
((k++))
|
||||||
if [[ $i -lt $arg_count && "${args[$i]}" != -* ]]; then
|
if [[ $k -lt $su_count && "${su_expanded[$k]}" != -* ]]; then
|
||||||
((i++))
|
((k++))
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
((i++))
|
((k++))
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [[ -z "$su_user" ]]; then
|
if [[ -z "$su_user" ]]; then
|
||||||
su_user="${args[$i]}"
|
su_user="${su_expanded[$k]}"
|
||||||
((i++))
|
((k++))
|
||||||
else
|
else
|
||||||
((i++))
|
((k++))
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -110,8 +155,9 @@ if [ -z "$sudo_command" ]; then
|
|||||||
sudo_command="exec /bin/bash --rcfile \"\$WSCOMPAT_DIR/bashrc\""
|
sudo_command="exec /bin/bash --rcfile \"\$WSCOMPAT_DIR/bashrc\""
|
||||||
fi
|
fi
|
||||||
if [ "$sudo_login_shell" ]; then
|
if [ "$sudo_login_shell" ]; then
|
||||||
bash_flags="--login --noprofile --norc";
|
exec /bin/sudo -u "$sudo_user" \
|
||||||
|
/bin/bash --login --noprofile --norc -c "$init_cmd; cd; $sudo_command"
|
||||||
else
|
else
|
||||||
bash_flags="--noprofile --norc";
|
exec /bin/sudo -u "$sudo_user" \
|
||||||
|
/bin/bash --noprofile --norc -c "$init_cmd; $sudo_command"
|
||||||
fi
|
fi
|
||||||
exec /bin/sudo -u "$sudo_user" /bin/bash $bash_flags -c "$init_cmd; $sudo_command"
|
|
||||||
|
@ -17,6 +17,13 @@ cat << 'WSCOMPAT_EOF_04tcIQE7' > "$WSCOMPAT_DIR/bashrc"
|
|||||||
stty intr ^K
|
stty intr ^K
|
||||||
alias ssh='wssh'
|
alias ssh='wssh'
|
||||||
alias sudo='wsudo'
|
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user