mirror of
https://mau.dev/andreijiroh-dev/dotfiles.git
synced 2025-01-31 11:43:39 +00:00
chore(global): add ~vern's bash prompt and stuff
Also in this commit: * Update shellrc files for bash for compat with this. I might work on adding checks for oh-my-posh later on. Signed-off-by: Andrei Jiroh Halili <ajhalili2006@gmail.com>
This commit is contained in:
parent
e7972d70d2
commit
dfa46de643
8 changed files with 298 additions and 13 deletions
11
.bash_login
11
.bash_login
|
@ -9,13 +9,4 @@ if [[ -f "$HOME/.env.local" ]]; then
|
|||
export LOCAL_DOTENV_LOADED=true
|
||||
fi
|
||||
|
||||
# Stage 1: Load global bashrc
|
||||
if [[ -f "$HOME/.bashrc" ]]; then
|
||||
source "$HOME/.bashrc"
|
||||
fi
|
||||
|
||||
# Stage 2: Machine specifcs
|
||||
if [[ -f $HOST_SPECIFIC_BASHRC ]]; then
|
||||
source "$HOST_SPECIFIC_BASHRC_PATH"
|
||||
export HOST_SPECIFIC_BASHRC_LOADED=true
|
||||
fi
|
||||
source "$HOME/.profile"
|
||||
|
|
4
.bashrc
4
.bashrc
|
@ -51,3 +51,7 @@ fi
|
|||
export HOMEBREW_HOME=${HOMEBREW_HOME:-"/home/linuxbrew/.linuxbrew"}
|
||||
test -d "$HOMEBREW_HOME" && eval "$($HOMEBREW_HOME/bin/brew shellenv)"
|
||||
[[ -r "$HOMEBREW_HOME/etc/profile.d/bash_completion.sh" ]] && . "$HOMEBREW_HOME/etc/profile.d/bash_completion.sh"
|
||||
|
||||
for file in "$HOME/.config/bash/${HOSTNAME}.bash" "$HOME/.config/bash/prompt" "${HOME}/.config/bash/bashrc"; do
|
||||
[ -f $file ] && . "$file"
|
||||
done
|
||||
|
|
5
.config/bash/README.md
Normal file
5
.config/bash/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# bashrc configurations
|
||||
|
||||
Host-specifics (including in `~vern`), maybe bash-specific functions.
|
||||
Global configs are at [`~/.bashrc`](../../.bashrc),
|
||||
[`~/.bash_login`](../../.bash_login) and [POSIX-compliant `~/.profile`](../../.profile).
|
109
.config/bash/bashrc
Normal file
109
.config/bash/bashrc
Normal file
|
@ -0,0 +1,109 @@
|
|||
# ~/.bashrc: executed by bash(1) for non-login shells.
|
||||
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
|
||||
# for examples
|
||||
|
||||
# If not running interactively, don't do anything
|
||||
case $- in
|
||||
*i*) ;;
|
||||
*) return;;
|
||||
esac
|
||||
|
||||
# don't put duplicate lines or lines starting with space in the history.
|
||||
# See bash(1) for more options
|
||||
HISTCONTROL=ignoreboth
|
||||
|
||||
# append to the history file, don't overwrite it
|
||||
shopt -s histappend
|
||||
|
||||
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
|
||||
HISTSIZE=1000
|
||||
HISTFILESIZE=2000
|
||||
|
||||
# check the window size after each command and, if necessary,
|
||||
# update the values of LINES and COLUMNS.
|
||||
shopt -s checkwinsize
|
||||
|
||||
# If set, the pattern "**" used in a pathname expansion context will
|
||||
# match all files and zero or more directories and subdirectories.
|
||||
#shopt -s globstar
|
||||
|
||||
# make less more friendly for non-text input files, see lesspipe(1)
|
||||
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
|
||||
# set variable identifying the chroot you work in (used in the prompt below)
|
||||
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
|
||||
debian_chroot=$(cat /etc/debian_chroot)
|
||||
fi
|
||||
|
||||
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||
case "$TERM" in
|
||||
xterm-color|*-256color) color_prompt=yes;;
|
||||
esac
|
||||
|
||||
# uncomment for a colored prompt, if the terminal has the capability; turned
|
||||
# off by default to not distract the user: the focus in a terminal window
|
||||
# should be on the output of commands, not on the prompt
|
||||
#force_color_prompt=yes
|
||||
|
||||
if [ -n "$force_color_prompt" ]; then
|
||||
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
|
||||
# We have color support; assume it's compliant with Ecma-48
|
||||
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
|
||||
# a case would tend to support setf rather than setaf.)
|
||||
color_prompt=yes
|
||||
else
|
||||
color_prompt=
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$color_prompt" = yes ]; then
|
||||
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
|
||||
else
|
||||
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
|
||||
fi
|
||||
unset color_prompt force_color_prompt
|
||||
|
||||
# If this is an xterm set the title to user@host:dir
|
||||
case "$TERM" in
|
||||
xterm*|rxvt*)
|
||||
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
|
||||
# enable color support of ls and also add handy aliases
|
||||
if [ -x /usr/bin/dircolors ]; then
|
||||
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
||||
alias ls='ls --color=auto'
|
||||
#alias dir='dir --color=auto'
|
||||
#alias vdir='vdir --color=auto'
|
||||
|
||||
#alias grep='grep --color=auto'
|
||||
#alias fgrep='fgrep --color=auto'
|
||||
#alias egrep='egrep --color=auto'
|
||||
fi
|
||||
|
||||
# colored GCC warnings and errors
|
||||
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
|
||||
|
||||
# some more ls aliases
|
||||
#alias ll='ls -l'
|
||||
#alias la='ls -A'
|
||||
#alias l='ls -CF'
|
||||
|
||||
# Alias definitions.
|
||||
# You may want to put all your additions into a separate file like
|
||||
# ~/.bash_aliases, instead of adding them here directly.
|
||||
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
|
||||
|
||||
# enable programmable completion features (you don't need to enable
|
||||
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
|
||||
# sources /etc/bash.bashrc).
|
||||
if ! shopt -oq posix; then
|
||||
if [ -f /usr/share/bash-completion/bash_completion ]; then
|
||||
. /usr/share/bash-completion/bash_completion
|
||||
elif [ -f /etc/bash_completion ]; then
|
||||
. /etc/bash_completion
|
||||
fi
|
||||
fi
|
171
.config/bash/prompt
Normal file
171
.config/bash/prompt
Normal file
|
@ -0,0 +1,171 @@
|
|||
#!/bin/bash
|
||||
# shebang for syntax highlighting purposes
|
||||
|
||||
# Colors
|
||||
_NON="\[\033[0m\]"
|
||||
_BLD="\[\033[1m\]" # YEP BALD
|
||||
_BLK="\[\033[30m\]"
|
||||
_RED="\[\033[31m\]"
|
||||
_GRN="\[\033[32m\]"
|
||||
_YLW="\[\033[33m\]"
|
||||
_BLU="\[\033[34m\]"
|
||||
_PRP="\[\033[35m\]"
|
||||
_CYN="\[\033[36m\]"
|
||||
_WHT="\[\033[37m\]"
|
||||
|
||||
__debug_trap() {
|
||||
# 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
|
||||
INC_TIME=1
|
||||
LAST_RT="$EPOCHREALTIME" # This should be the last thing done in this function
|
||||
fi
|
||||
LAST_BASH_COMMAND="$BASH_COMMAND"
|
||||
}
|
||||
|
||||
trap '__debug_trap' DEBUG
|
||||
|
||||
__get_cmd_time() {
|
||||
# Set hours minutes seconds and remove preceding zeros
|
||||
local YEAR=$((10#0$(($(TZ=UTC printf '%(%Y)T' $CMD_TIME)))-1970))
|
||||
local DAYS=$((10#0$(TZ=UTC printf '%(%j)T' $CMD_TIME)))
|
||||
local HOUR=$((10#0$(TZ=UTC printf '%(%H)T' $CMD_TIME)))
|
||||
local MINS=$((10#0$(TZ=UTC printf '%(%M)T' $CMD_TIME)))
|
||||
local SECS=$((10#0$(TZ=UTC printf '%(%S)T' $CMD_TIME)))
|
||||
|
||||
# Choose whether or not to print hours minutes and seconds
|
||||
[[ $CMD_TIME -ge 31536000 ]] && printf '%sy ' ${YEAR}
|
||||
[[ $CMD_TIME -ge 86400 ]] && printf '%sd ' ${DAYS}
|
||||
[[ $CMD_TIME -ge 3600 ]] && printf '%sh ' ${HOUR}
|
||||
[[ $CMD_TIME -ge 60 ]] && printf '%sm ' ${MINS}
|
||||
[[ $CMD_TIME -ge 1 ]] && printf '%ss ' ${SECS}
|
||||
# If you want to have a limit uncomment the next line and replace somenum with
|
||||
# the minimum microseconds
|
||||
# [[ $CMD_US -ge somenum ]] &&
|
||||
printf '%sμs' ${CMD_US:-0}
|
||||
}
|
||||
|
||||
__sig() {
|
||||
# Giant switch case for getting the name of the signal (`kill -l`)
|
||||
j=0
|
||||
for i in $@; do
|
||||
if [[ $j != 0 ]]; then
|
||||
printf '%s|%s' "$_WHT" "$_RED"
|
||||
fi
|
||||
j=$((j+1))
|
||||
case $i in
|
||||
126) printf ACCES ;;
|
||||
127) printf NOENT ;;
|
||||
129) printf HUP ;;
|
||||
130) printf INT ;;
|
||||
131) printf QUIT ;;
|
||||
132) printf ILL ;;
|
||||
133) printf TRAP ;;
|
||||
134) printf ABRT ;;
|
||||
135) printf BUS ;;
|
||||
136) printf FPE ;;
|
||||
137) printf KILL ;;
|
||||
138) printf USR1 ;;
|
||||
139) printf SEGV ;;
|
||||
140) printf USR2 ;;
|
||||
141) printf PIPE ;;
|
||||
142) printf ALRM ;;
|
||||
143) printf TERM ;;
|
||||
144) printf STKFLT ;;
|
||||
145) printf CHLD ;;
|
||||
146) printf CONT ;;
|
||||
147) printf STOP ;;
|
||||
148) printf TSTP ;;
|
||||
149) printf TTIN ;;
|
||||
150) printf TTOU ;;
|
||||
151) printf URG ;;
|
||||
152) printf XCPU ;;
|
||||
153) printf XFSZ ;;
|
||||
154) printf VTALRM ;;
|
||||
155) printf PROF ;;
|
||||
156) printf WINCH ;;
|
||||
157) printf IO ;;
|
||||
158) printf PWR ;;
|
||||
159) printf SYS ;;
|
||||
16[3-9]|1[7-8][0-9]|19[0-2]) printf RT$(($i-128)) ;; # Savagery
|
||||
*) printf $i ;; # Print exit code if not in list
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
__ssh() {
|
||||
local CON=($SSH_CONNECTION)
|
||||
local SRV_IP="${CON[2]}"
|
||||
[[ -z "$SRV_IP" ]] && return
|
||||
local SRV_PORT="${CON[3]}"
|
||||
# 4 chars from startand 4 chars from end
|
||||
local SRV_IP_CUT="${_CYN}${SRV_IP}"
|
||||
[[ ${#SRV_IP} -gt 8 ]] && local SRV_IP_CUT="${_CYN}${SRV_IP:0:4}${_WHT}*${_CYN}${SRV_IP: -4}"
|
||||
|
||||
printf '%s' "${_GRN}${_BLU}[${SRV_IP_CUT}${_PRP}${_BLD}:${_NON}${_CYN}${SRV_PORT}${_BLU}]${_NON}"
|
||||
}
|
||||
|
||||
__prompt() {
|
||||
# Get exit code (must be first)
|
||||
local PLC=(${PIPESTATUS[@]})
|
||||
|
||||
# Reset time when prompt was first displayed after command
|
||||
# this contributes to the 40 microsecond difference in $CMD_US and the actual time it took
|
||||
if [[ "$INC_TIME" != 0 ]]; then
|
||||
PROMPT_RT="$EPOCHREALTIME"
|
||||
INC_TIME=0
|
||||
fi
|
||||
|
||||
# *_RT may not be set
|
||||
LAST_RT="${LAST_RT:-$EPOCHREALTIME}"
|
||||
PROMPT_RT="${PROMPT_RT:-$EPOCHREALTIME}"
|
||||
|
||||
# Get relative times
|
||||
|
||||
# Remove decimal point, simulating multiplying by 1 million
|
||||
PROMPT_RT1M="${PROMPT_RT/.}"
|
||||
LAST_RT1M="${LAST_RT/.}"
|
||||
|
||||
CMD_US="$(($PROMPT_RT1M-$LAST_RT1M))"
|
||||
|
||||
CMD_TIME=0
|
||||
|
||||
# Remove last 6 chars, simulating dividing by 1 million to get a more accurate difference
|
||||
[[ ${#CMD_US} -lt 6 ]] || CMD_TIME="${CMD_US::-6}"
|
||||
|
||||
[[ ${#CMD_US} -lt 6 ]] || CMD_US="${CMD_US: -6}"
|
||||
CMD_US="$((10#0$CMD_US))"
|
||||
|
||||
# Set prompt sections
|
||||
|
||||
# Text
|
||||
|
||||
# ssh detection and indicator
|
||||
[[ "$SSH_CONNECTION" ]] && local SSH="$(__ssh) "
|
||||
|
||||
# [INT], [4], etc.
|
||||
local i
|
||||
for i in ${PLC[@]}; do
|
||||
if [[ $i > 0 ]]; then
|
||||
local SIG="$(printf '%s[%s%s%s] ' "$_BLU" "$_RED" "$(__sig ${PLC[@]})" "$_BLU")"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# [user@homeserver:~]
|
||||
local COL="$([[ $UID == 0 ]] && printf '%s' "$_RED" || printf '%s' "$_YLW")"
|
||||
local UHD="${_BLD}${_BLU}[${COL}\u${_PRP}@${_CYN}\h${_PRP}:${_GRN}\w${_BLU}]"
|
||||
|
||||
# 2y 351d 12m 43s 382969μs
|
||||
local TIME="${_YLW}$(__get_cmd_time)"
|
||||
|
||||
# Random colored $ or #
|
||||
_RAND256="\[\033[38;2;$((RANDOM%256));$((RANDOM%256));$((RANDOM%256))m\]"
|
||||
local IND="${_RAND256}\\$"
|
||||
|
||||
# Set the prompt
|
||||
PS1="${_NON}${SSH}${SIG}${UHD} ${TIME} ${IND} ${_NON}"
|
||||
}
|
||||
|
||||
PROMPT_COMMAND=__prompt
|
|
@ -11,6 +11,7 @@ aliases:
|
|||
co: pr checkout
|
||||
clone: repo clone
|
||||
mr: pr
|
||||
fork: repo fork
|
||||
# The path to a unix socket through which send HTTP connections. If blank, HTTP traffic will be handled by net/http.DefaultTransport.
|
||||
http_unix_socket:
|
||||
# What web browser gh should use when opening URLs. If blank, will refer to environment.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Beware! This file is rewritten by htop when settings are changed in the interface.
|
||||
# The parser is also very primitive, and not human-friendly.
|
||||
htop_version=3.2.1
|
||||
htop_version=3.2.0
|
||||
config_reader_min_version=3
|
||||
fields=0 48 17 18 38 39 40 2 46 47 49 1
|
||||
hide_kernel_threads=1
|
||||
|
@ -38,14 +38,14 @@ column_meters_1=Tasks LoadAverage Uptime
|
|||
column_meter_modes_1=2 2 2
|
||||
tree_view=1
|
||||
sort_key=46
|
||||
tree_sort_key=0
|
||||
tree_sort_key=48
|
||||
sort_direction=-1
|
||||
tree_sort_direction=1
|
||||
tree_view_always_by_pid=0
|
||||
all_branches_collapsed=0
|
||||
screen:Main=PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command
|
||||
.sort_key=PERCENT_CPU
|
||||
.tree_sort_key=PID
|
||||
.tree_sort_key=USER
|
||||
.tree_view=1
|
||||
.tree_view_always_by_pid=0
|
||||
.sort_direction=-1
|
||||
|
|
4
.profile
4
.profile
|
@ -7,5 +7,9 @@ if [ -n "$BASH_VERSION" ]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
export PATH="/usr/local/bin${PATH:+:}$PATH" # ~vern specifics, might work on this soon.
|
||||
mesg n 2> /dev/null || true
|
||||
|
||||
# then import the rest
|
||||
source "$HOME/.env"
|
||||
source "$HOME/.config/aliases"
|
||||
|
|
Loading…
Reference in a new issue