Skip to content

Commit

Permalink
Merge branch 'new-prompt-enhanements' into suse
Browse files Browse the repository at this point in the history
* new-prompt-enhanements:
  monster_prompt with files and load average
  • Loading branch information
sinewalker committed Apr 2, 2018
2 parents 233284e + eb0ef33 commit 0fde7d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions source/10_meta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function is_exe() {
}


function is_linux() {
local FUNCDESC="Test if the operating system is a Linux flavour"
[[ $(uname) =~ Linux ]] || return 1
}

### MJL20180314 Function introspection

Expand Down
29 changes: 22 additions & 7 deletions source/20_prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,14 @@ function __prompt_conda() {

#MJL20170218 files and size count (from "monster prompt" in my ancient dotfiles)
function __prompt_sizes() {
is_osx && alias __llssi='gls --si -sl' || alias __llssi='ls --si -sl'
__llssi|awk '/total/{TOTAL=$2} /(.*) (-.*)/{FILES=FILES+1} END{print FILES " files, " TOTAL}'
unalias __lsssi
echo "${C1}(${C9}$(ls --si -al|awk '/total/{TOTAL=$2} END{print NR-1 " files, " TOTAL}')${C1})${C9}"
}

#MJL20170218 CPU load and uptime (from monster prompt -- DAFT)
function __prompt_cpu() {
$(cat /proc/loadavg)
$(temp=$(cat /proc/uptime) && upSec=${temp%%.*} ; let secs=$((${upSec}%60)) ; let mins=$((${upSec}/60%60)) ; let hours=$((${upSec}/3600%24)) ; let days=$((${upSec}/86400)) ; if [ ${days} -ne 0 ]; then echo -n ${days}d; fi ; echo -n ${hours}h${mins}m)

local upt=$(uptime|awk '{gsub(",",""); print $3 }')
local lda=$(uptime|awk '{gsub(",",""); print $8}')
echo "${C1}[${C0}Up ${C4}${upt}${C0} Load ${C5}${lda}${C1}]${C9}"
}

#MJL20170205 toggle using a simple prompt
Expand All @@ -177,7 +175,18 @@ function prompt_simple() {
}
alias simple_prompt=prompt_simple
alias awesome_prompt=prompt_simple
alias monster_prompt=prompt_simple

#MJL20180402 toggle using monster prompt
# If an argument is supplied, force it to simple
function prompt_monster() {
local FUNCDESC="Toggle using a monster prompt. If an argument is supplied, force to simple"
if [[ -z ${__USE_MONSTER_PROMPT} || -n "${1}" ]]; then
export __USE_MONSTER_PROMPT=1
else
unset __USE_MONSTER_PROMPT
fi
}
alias monster_prompt=prompt_monster

#MJL20170207 toggle command history trace
# sometimes this can be useful
Expand Down Expand Up @@ -236,8 +245,14 @@ function __prompt_command() {
PS1="${PS1}$(__prompt_hg)"
# path: [user@host:path]
PS1="${PS1}${C1}[${C0}\u${C1}@${C0}\h${C1}:${C0}\w${C1}]${C9}"
if [[ -n ${__USE_MONSTER_PROMPT} ]]; then
PS1="${PS1}$(__prompt_sizes)"
fi
PS1="${PS1}\n"

if [[ -n ${__USE_MONSTER_PROMPT} ]]; then
PS1="${PS1}$(__prompt_cpu)"
fi
#MJL20170205 screen: #
PS1="${PS1}$(__prompt_screen)"
#MJL20170207 turn on the command history trace if wanted
Expand Down

0 comments on commit 0fde7d0

Please sign in to comment.