-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsu
More file actions
44 lines (39 loc) · 964 Bytes
/
Copy pathsu
File metadata and controls
44 lines (39 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/data/data/com.termux/files/usr/bin/env bash
# Normal interactive su wrapper
# Reads normal rc/profile, fake $0, PS1 (~ + $PREFIX->/), -c, pipes
# -------------------------------
# 1️⃣ Fake $0 for echo
echo_func() {
if [[ "$1" == "\$0" ]]; then
printf "su\n"
else
command echo "$@"
fi
}
alias echo='echo_func'
# -------------------------------
# 2️⃣ PS1 builder function
build_prompt() {
local dir="${PWD/#$PREFIX//}" # Replace $PREFIX prefix with /
if [[ "$dir" == "$HOME"* ]]; then
dir="~${dir#$HOME}" # Replace home with ~
fi
PS1=" $dir # "
}
PROMPT_COMMAND=build_prompt
# -------------------------------
# 3️⃣ Pipe input
if [ ! -t 0 ]; then
bash -s
exit
fi
# -------------------------------
# 4️⃣ -c command
if [ "$1" = "-c" ] && [ $# -ge 2 ]; then
shift
bash -c "$*"
exit
fi
# -------------------------------
# 5️⃣ Default interactive shell
exec bash