Fix prompt startup bug and update bashrc

This commit is contained in:
The Cobra 2022-03-02 10:58:27 -05:00
parent 6cbdffe340
commit ca6b934c80
3 changed files with 53 additions and 24 deletions

28
.bashrc
View File

@ -1,6 +1,13 @@
. ~/.prompt
# History stuff
export HISTCONTROL=ignoredups:erasedups
export HISTFILESIZE=1000
export HISTSIZE=1000
# We hate sudo here
alias sudo='sh -c "exit 1"'
# Other aliases
alias c='clear'
alias ls='ls --color=auto -FAh'
alias ll='ls -l'
@ -8,20 +15,35 @@ alias rebash='. ~/.bashrc'
alias bashrc="$EDITOR ~/.bashrc && rebash"
alias nf='neofetch'
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() {
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'; }
# Im too lazy to type
copy() {
tee >(wl-copy)
}
# Source colors for tty
. ~/.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() {
old_lc_collate=$LC_COLLATE
LC_COLLATE_OLD=$LC_COLLATE
LC_COLLATE=C
local TEXT="$(</dev/stdin)"
@ -33,5 +55,5 @@ urlencode() {
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
LC_COLLATE=$LC_COLLATE_OLD
}

View File

@ -3,3 +3,4 @@ export SXMO_WORKSPACE_WRAPPING=5
export EDITOR=vim
export INVIDIOUS="https://invidious.snopyta.org"
export PATH="$HOME/.local/bin:$PATH"
[ -r ~/.bashrc ] && . ~/.bashrc

48
.prompt
View File

@ -2,11 +2,11 @@
# shebang for syntax highlightin purposes
__debug_trap() {
# Set necessary pre-command variables (PROMPT_COMMAND is a command
# so its excluded here)
# Set necessary pre-command variables (PROMPT_COMMAND is a
# command so its excluded here)
if [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" &&
"$LAST_BASH_COMMAND" == "$PROMPT_COMMAND" ]]; then
LAST_REALTIME="$EPOCHREALTIME"
LAST_RT="$EPOCHREALTIME"
INC_TIME=1
fi
LAST_BASH_COMMAND="$BASH_COMMAND"
@ -16,19 +16,20 @@ trap '__debug_trap' DEBUG
__get_cmd_time() {
# Set hours minutes seconds and remove preceding zeros
local YEAR=$(($((10#$(TZ=UTC printf '%(%Y)T' $CMD_TIME)))-1970))
local DAYS=$((10#$(TZ=UTC printf '%(%j)T' $CMD_TIME)))
local HOUR=$((10#$(TZ=UTC printf '%(%H)T' $CMD_TIME)))
local MINS=$((10#$(TZ=UTC printf '%(%M)T' $CMD_TIME)))
local SECS=$((10#$(TZ=UTC printf '%(%S)T' $CMD_TIME))) #wtf sex???
TZ=UTC
local YEAR=$(($((10#$(printf '%(%Y)T' $CMD_TIME)))-1970))
local DAYS=$((10#$(printf '%(%j)T' $CMD_TIME)))
local HOUR=$((10#$(printf '%(%H)T' $CMD_TIME)))
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
[ $CMD_TIME -ge 31536000 ] && TZ=UTC printf '%sd ' ${YEAR:-0}
[ $CMD_TIME -ge 86400 ] && TZ=UTC printf '%sd ' ${DAYS:-0}
[ $CMD_TIME -ge 3600 ] && TZ=UTC printf '%sh ' ${HOUR:-0}
[ $CMD_TIME -ge 60 ] && TZ=UTC printf '%sm ' ${MINS:-0}
[ $CMD_TIME -ge 1 ] && TZ=UTC printf '%ss ' ${SECS:-0}
TZ=UTC printf '%sμs' ${CMD_US:-0}
[ $CMD_TIME -ge 31536000 ] && printf '%sd ' ${YEAR:-0}
[ $CMD_TIME -ge 86400 ] && printf '%sd ' ${DAYS:-0}
[ $CMD_TIME -ge 3600 ] && printf '%sh ' ${HOUR:-0}
[ $CMD_TIME -ge 60 ] && printf '%sm ' ${MINS:-0}
[ $CMD_TIME -ge 1 ] && printf '%ss ' ${SECS:-0}
printf '%sμs' ${CMD_US:-0}
}
__sig() {
@ -73,25 +74,30 @@ __sig() {
}
__prompt() {
# LAST_RT is not set before a command is run
LAST_RT="${LAST_RT:-$EPOCHREALTIME}"
# Get exit code
local PEC=$?
local PEC=${?:-0}
# Reset time when prompt was first displayed after command
if [ $INC_TIME -ne 0 ]; then
PROMPT_REALTIME="$EPOCHREALTIME"
if [ ${INC_TIME:-1} -ne 0 ]; then
PROMPT_RT="$EPOCHREALTIME"
INC_TIME=0
fi
# Get relative times
# Remove decimal point, simulating multiplying by 1 million
PROMPT_RT1M="${PROMPT_REALTIME%.*}${PROMPT_REALTIME#*.}"
LAST_RT1M="${LAST_REALTIME%.*}${LAST_REALTIME#*.}"
PROMPT_RT1M="${PROMPT_RT%.*}${PROMPT_RT#*.}"
LAST_RT1M="${LAST_RT%.*}${LAST_RT#*.}"
# Subtract and divide by 1 million to get a more accurate difference
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 PROMPT_US="${PROMPT_REALTIME: -6}"
local PROMPT_US="${PROMPT_RT: -6}"
local PROMPT_US_CLN="$((10#$PROMPT_US))"
local PROMPT_US_CLN="${PROMPT_US_CLN:-0}"