Skip to content

Commit b0297a8

Browse files
authored
Add files via upload
1 parent d507284 commit b0297a8

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

Cachyos/Scripts/Android/mkshrc.sh

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# If not running interactively, don't do anything
2+
[[ $- != *i* ]] && return
3+
4+
# --- Keybindings ---
5+
# These work universally as they are mksh/terminal features
6+
set -o emacs
7+
bind '"\e[1;5D"=backward-word' # Ctrl+Left
8+
bind '"\e[1;5C"=forward-word' # Ctrl+Right
9+
bind '"\e[A"=search-history-up' # Up arrow history search
10+
bind '"\e[B"=search-history-down' # Down arrow history search
11+
bind ^[a=beginning-of-line
12+
bind ^[e=end-of-line
13+
14+
export HISTCONTROL="ignoredups:ignorespace"
15+
16+
# Report status of background jobs immediately upon completion
17+
set -o notify
18+
# Run background jobs at a lower priority (also disables the bell)
19+
set -o bgnice
20+
# Prevent accidental overwrites when redirecting output with >
21+
# Use >| to force an overwrite.
22+
set -o noclobber
23+
# Function to create a directory and move into it
24+
set +o nohup # disable nohup mode
25+
set -o utf8-mode
26+
27+
mkcd() {
28+
mkdir -p "$1" && cd "$1"
29+
}
30+
cdl() {
31+
cd "$1" && ls -a --color=auto
32+
}
33+
34+
35+
CDPATH=".:~:/sdcard:/sdcard/Android/data:/:/storage/emulated/0"
36+
export CDPATH
37+
38+
# File patterns to ignore during tab completion
39+
export FIGNORE='.o:~:*.swp'
40+
41+
alias grep='grep --color=auto'
42+
# Package Manager (pm)
43+
alias pml='pm list packages'
44+
alias pml3='pm list packages -3' # 3rd party only
45+
alias pmp='pm path'
46+
alias pmd='pm dump'
47+
48+
# Logcat
49+
alias lc='logcat -v brief'
50+
alias lct='logcat -v threadtime'
51+
alias lce='logcat *:E' # Errors only
52+
53+
# Some usefull aliases
54+
alias ls="ls --color=auto -FA"
55+
alias l="ls --color=auto -Fl"
56+
alias ll="ls --color=auto -FAl"
57+
alias la="ls --color=auto -Fa"
58+
59+
alias cls=clear
60+
61+
alias ..="cd ../"
62+
alias ....="cd ../../"
63+
alias ......="cd ../../../"
64+
alias ........="cd ../../../../"
65+
66+
# Show current focused app and activity
67+
current_activity() {
68+
dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
69+
}
70+
71+
# a function to help users find the local ip (from gh:omz/sysadmin plugin)
72+
myip(){
73+
if [ -x "$(command -v 'ip')" ]; then
74+
ip addr | awk '/inet /{print $2}' | grep -v 127.0.0.1
75+
else
76+
ifconfig | awk '/inet /{print $2}' | grep -v 127.0.0.1
77+
fi
78+
}
79+
80+
# Basic replacement for "man" since Android usually lacks it
81+
function man() {
82+
local binary="$(_resolve "$1" | cut -d ' ' -f1)"
83+
84+
# Handle empty or recursive call (man man)
85+
if [ -z "$binary" ] || [ "$binary" = 'man' ]; then
86+
echo -e "What manual page do you want?\nFor example, try 'man ls'." >&2
87+
return 1
88+
fi
89+
90+
# Use --help output as a poor-man’s manual
91+
local manual="$("$binary" --help 2>&1)"
92+
if [ $? -eq 127 ] || [ -z "$manual" ]; then
93+
echo "No manual entry for $binary" >&2
94+
return 16
95+
fi
96+
97+
$binary --help
98+
}
99+
export man
100+
101+
# Function to simulate 'man' command
102+
man() {
103+
[ -z "$1" ] && { echo -e "What manual page do you want?\nFor example, try 'man ls'." >&2; return 1; }
104+
"$1" --help >/dev/null 2>&1 && "$1" --help 2>&1 || { echo "No manual entry for $1" >&2; return 16; }
105+
}
106+
107+
# --- 1. Define Colors ---
108+
MGN=$'\e[35m'; BLU=$'\e[34m'; YLW=$'\e[33m'; BLD=$'\e[1m'; UND=$'\e[4m'
109+
GRN=$'\e[32m'; CYN=$'\e[36m'; DEF=$'\e[0m'; RED=$'\e[31m'; PNK=$'\e[38;5;205m'
110+
111+
# --- 2. Set the PS1 evaluation string ---
112+
PS1='
113+
local ret=$?
114+
# --- User ---
115+
local USERN="${MGN}$USER${DEF}"
116+
(( EUID == 0 )) && USERN="${RED}$USER${DEF}"
117+
# --- Hostname ---
118+
local HOSTL="${BLU}${HOSTNAME:-$(hostname -s)}${DEF}"
119+
# Check for an SSH connection (this also works for sshd on-device).
120+
[[ -n $SSH_CONNECTION ]] && HOSTL="${YLW}${HOSTNAME:-$(hostname -s)}${DEF}"
121+
# --- Working Directory ---
122+
local WDIR="${CYN}${PWD/#$HOME/~}${DEF}"
123+
# --- Time ---
124+
# %H:%M gives the 24-hour time
125+
local TIME="${PNK}$(date +%H:%M)${DEF}"
126+
# --- Exit Status Indicator ---
127+
local EXSTAT
128+
if (( ret == 0 )); then
129+
EXSTAT="${GRN}:)${DEF}"
130+
else
131+
EXSTAT="${RED}D:${DEF}"
132+
fi
133+
# --- Prompt Character ---
134+
# Sets "#" for root, "$" for normal users
135+
local PCHAR="$"
136+
(( EUID == 0 )) && PCHAR="#"
137+
local BOLD_PCHAR="${BLD}${PCHAR}${DEF}"
138+
# --- Final Assembly ---
139+
# Assembles the prompt string
140+
print -n "[${USERN}@${HOSTL}${UND}|${DEF}${WDIR}]>${TIME}|${EXSTAT} ${BOLD_PCHAR} "
141+
'
142+
PS2='> '
143+
# Keep PS4 with timestamps
144+
PS4='[$EPOCHREALTIME] '

0 commit comments

Comments
 (0)