Fix prompt startup bug and update bashrc
This commit is contained in:
parent
6cbdffe340
commit
ca6b934c80
28
.bashrc
28
.bashrc
|
@ -1,6 +1,13 @@
|
||||||
. ~/.prompt
|
. ~/.prompt
|
||||||
|
|
||||||
|
# History stuff
|
||||||
|
export HISTCONTROL=ignoredups:erasedups
|
||||||
|
export HISTFILESIZE=1000
|
||||||
|
export HISTSIZE=1000
|
||||||
|
|
||||||
|
# We hate sudo here
|
||||||
alias sudo='sh -c "exit 1"'
|
alias sudo='sh -c "exit 1"'
|
||||||
|
# Other aliases
|
||||||
alias c='clear'
|
alias c='clear'
|
||||||
alias ls='ls --color=auto -FAh'
|
alias ls='ls --color=auto -FAh'
|
||||||
alias ll='ls -l'
|
alias ll='ls -l'
|
||||||
|
@ -8,20 +15,35 @@ alias rebash='. ~/.bashrc'
|
||||||
alias bashrc="$EDITOR ~/.bashrc && rebash"
|
alias bashrc="$EDITOR ~/.bashrc && rebash"
|
||||||
alias nf='neofetch'
|
alias nf='neofetch'
|
||||||
alias sshd='boas /usr/sbin/sshd'
|
alias sshd='boas /usr/sbin/sshd'
|
||||||
|
|
||||||
|
# Completions for elevation program (https://codeberg.org/Bowuigi/Unit21 in management/boas)
|
||||||
|
complete -cf boas
|
||||||
|
|
||||||
|
# Random string (passwords)
|
||||||
|
randstr() { tr -cd [:graph:] </dev/urandom | head -c${1:-256}; }
|
||||||
|
|
||||||
|
# Get CPU usage
|
||||||
cpusage() {
|
cpusage() {
|
||||||
bc<<<"scale=3;$(ps aux | awk 'BEGIN {sum=0} {sum+=$3}; END {print sum}') / $(nproc --all)"
|
bc<<<"scale=3;$(ps aux | awk 'BEGIN {sum=0} {sum+=$3}; END {print sum}') / $(nproc --all)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Update and upgrade system
|
||||||
update() { boas sh -c 'apk update && apk upgrade -aiv'; }
|
update() { boas sh -c 'apk update && apk upgrade -aiv'; }
|
||||||
|
|
||||||
|
# Im too lazy to type
|
||||||
copy() {
|
copy() {
|
||||||
tee >(wl-copy)
|
tee >(wl-copy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Source colors for tty
|
||||||
. ~/.config/sxmo/isotope.dark
|
. ~/.config/sxmo/isotope.dark
|
||||||
lip() { ip a| grep wlan0 | sed 1d | cut -d' ' -f6 | cut -d/ -f1; }
|
|
||||||
|
# Get local IP
|
||||||
|
lip() { ip a | grep ${1:-wlan0} | sed 1d | cut -d' ' -f6 | cut -d/ -f1; }
|
||||||
|
|
||||||
|
# URL-encode stdin
|
||||||
urlencode() {
|
urlencode() {
|
||||||
old_lc_collate=$LC_COLLATE
|
LC_COLLATE_OLD=$LC_COLLATE
|
||||||
LC_COLLATE=C
|
LC_COLLATE=C
|
||||||
|
|
||||||
local TEXT="$(</dev/stdin)"
|
local TEXT="$(</dev/stdin)"
|
||||||
|
@ -33,5 +55,5 @@ urlencode() {
|
||||||
*) printf '%%%02X' "'$c" ;;
|
*) printf '%%%02X' "'$c" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
LC_COLLATE=$old_lc_collate
|
LC_COLLATE=$LC_COLLATE_OLD
|
||||||
}
|
}
|
||||||
|
|
1
.profile
1
.profile
|
@ -3,3 +3,4 @@ export SXMO_WORKSPACE_WRAPPING=5
|
||||||
export EDITOR=vim
|
export EDITOR=vim
|
||||||
export INVIDIOUS="https://invidious.snopyta.org"
|
export INVIDIOUS="https://invidious.snopyta.org"
|
||||||
export PATH="$HOME/.local/bin:$PATH"
|
export PATH="$HOME/.local/bin:$PATH"
|
||||||
|
[ -r ~/.bashrc ] && . ~/.bashrc
|
||||||
|
|
48
.prompt
48
.prompt
|
@ -2,11 +2,11 @@
|
||||||
# shebang for syntax highlightin purposes
|
# shebang for syntax highlightin purposes
|
||||||
|
|
||||||
__debug_trap() {
|
__debug_trap() {
|
||||||
# Set necessary pre-command variables (PROMPT_COMMAND is a command
|
# Set necessary pre-command variables (PROMPT_COMMAND is a
|
||||||
# so its excluded here)
|
# command so its excluded here)
|
||||||
if [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" &&
|
if [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" &&
|
||||||
"$LAST_BASH_COMMAND" == "$PROMPT_COMMAND" ]]; then
|
"$LAST_BASH_COMMAND" == "$PROMPT_COMMAND" ]]; then
|
||||||
LAST_REALTIME="$EPOCHREALTIME"
|
LAST_RT="$EPOCHREALTIME"
|
||||||
INC_TIME=1
|
INC_TIME=1
|
||||||
fi
|
fi
|
||||||
LAST_BASH_COMMAND="$BASH_COMMAND"
|
LAST_BASH_COMMAND="$BASH_COMMAND"
|
||||||
|
@ -16,19 +16,20 @@ trap '__debug_trap' DEBUG
|
||||||
|
|
||||||
__get_cmd_time() {
|
__get_cmd_time() {
|
||||||
# Set hours minutes seconds and remove preceding zeros
|
# Set hours minutes seconds and remove preceding zeros
|
||||||
local YEAR=$(($((10#$(TZ=UTC printf '%(%Y)T' $CMD_TIME)))-1970))
|
TZ=UTC
|
||||||
local DAYS=$((10#$(TZ=UTC printf '%(%j)T' $CMD_TIME)))
|
local YEAR=$(($((10#$(printf '%(%Y)T' $CMD_TIME)))-1970))
|
||||||
local HOUR=$((10#$(TZ=UTC printf '%(%H)T' $CMD_TIME)))
|
local DAYS=$((10#$(printf '%(%j)T' $CMD_TIME)))
|
||||||
local MINS=$((10#$(TZ=UTC printf '%(%M)T' $CMD_TIME)))
|
local HOUR=$((10#$(printf '%(%H)T' $CMD_TIME)))
|
||||||
local SECS=$((10#$(TZ=UTC printf '%(%S)T' $CMD_TIME))) #wtf sex???
|
local MINS=$((10#$(printf '%(%M)T' $CMD_TIME)))
|
||||||
|
local SECS=$((10#$(printf '%(%S)T' $CMD_TIME))) #wtf sex???
|
||||||
|
|
||||||
# Choose whether or not to print hours minutes and seconds
|
# Choose whether or not to print hours minutes and seconds
|
||||||
[ $CMD_TIME -ge 31536000 ] && TZ=UTC printf '%sd ' ${YEAR:-0}
|
[ $CMD_TIME -ge 31536000 ] && printf '%sd ' ${YEAR:-0}
|
||||||
[ $CMD_TIME -ge 86400 ] && TZ=UTC printf '%sd ' ${DAYS:-0}
|
[ $CMD_TIME -ge 86400 ] && printf '%sd ' ${DAYS:-0}
|
||||||
[ $CMD_TIME -ge 3600 ] && TZ=UTC printf '%sh ' ${HOUR:-0}
|
[ $CMD_TIME -ge 3600 ] && printf '%sh ' ${HOUR:-0}
|
||||||
[ $CMD_TIME -ge 60 ] && TZ=UTC printf '%sm ' ${MINS:-0}
|
[ $CMD_TIME -ge 60 ] && printf '%sm ' ${MINS:-0}
|
||||||
[ $CMD_TIME -ge 1 ] && TZ=UTC printf '%ss ' ${SECS:-0}
|
[ $CMD_TIME -ge 1 ] && printf '%ss ' ${SECS:-0}
|
||||||
TZ=UTC printf '%sμs' ${CMD_US:-0}
|
printf '%sμs' ${CMD_US:-0}
|
||||||
}
|
}
|
||||||
|
|
||||||
__sig() {
|
__sig() {
|
||||||
|
@ -73,25 +74,30 @@ __sig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__prompt() {
|
__prompt() {
|
||||||
|
# LAST_RT is not set before a command is run
|
||||||
|
LAST_RT="${LAST_RT:-$EPOCHREALTIME}"
|
||||||
|
|
||||||
# Get exit code
|
# Get exit code
|
||||||
local PEC=$?
|
local PEC=${?:-0}
|
||||||
|
|
||||||
# Reset time when prompt was first displayed after command
|
# Reset time when prompt was first displayed after command
|
||||||
if [ $INC_TIME -ne 0 ]; then
|
if [ ${INC_TIME:-1} -ne 0 ]; then
|
||||||
PROMPT_REALTIME="$EPOCHREALTIME"
|
PROMPT_RT="$EPOCHREALTIME"
|
||||||
INC_TIME=0
|
INC_TIME=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get relative times
|
# Get relative times
|
||||||
|
|
||||||
# Remove decimal point, simulating multiplying by 1 million
|
# Remove decimal point, simulating multiplying by 1 million
|
||||||
PROMPT_RT1M="${PROMPT_REALTIME%.*}${PROMPT_REALTIME#*.}"
|
PROMPT_RT1M="${PROMPT_RT%.*}${PROMPT_RT#*.}"
|
||||||
LAST_RT1M="${LAST_REALTIME%.*}${LAST_REALTIME#*.}"
|
LAST_RT1M="${LAST_RT%.*}${LAST_RT#*.}"
|
||||||
# Subtract and divide by 1 million to get a more accurate difference
|
# Subtract and divide by 1 million to get a more accurate difference
|
||||||
CMD_TIME="$(((PROMPT_RT1M-LAST_RT1M)/1000000))"
|
CMD_TIME="$(((PROMPT_RT1M-LAST_RT1M)/1000000))"
|
||||||
|
CMD_TIME="${CMD_TIME:-0}"
|
||||||
|
|
||||||
local LAST_US="$((10#${LAST_REALTIME: -6}))"
|
local LAST_US="$((10#${LAST_RT: -6}))"
|
||||||
local LAST_US="${LAST_US:-0}"
|
local LAST_US="${LAST_US:-0}"
|
||||||
local PROMPT_US="${PROMPT_REALTIME: -6}"
|
local PROMPT_US="${PROMPT_RT: -6}"
|
||||||
local PROMPT_US_CLN="$((10#$PROMPT_US))"
|
local PROMPT_US_CLN="$((10#$PROMPT_US))"
|
||||||
local PROMPT_US_CLN="${PROMPT_US_CLN:-0}"
|
local PROMPT_US_CLN="${PROMPT_US_CLN:-0}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue