From Cute Madrill, 1 Week ago, written in Plain Text.
  1. setprompt(){
  2.  
  3.     smacs="\033(0" rmacs="\033(B"
  4.     fg=( "\033[0;30m" "\033[0;31m" "\033[0;32m" "\033[0;33m" "\033[0;34m" "\033[0;35m" "\033[0;36m" "\033[0;37m"
  5.          "\033[0;90m" "\033[0;91m" "\033[0;92m" "\033[0;93m" "\033[0;94m" "\033[0;95m" "\033[0;96m" "\033[0;97m" )
  6.     bg=( "\033[0;40m" "\033[0;41m" "\033[0;42m" "\033[0;43m" "\033[0;44m" "\033[0;45m" "\033[0;46m" "\033[0;47m"
  7.          "\033[0;100m" "\033[0;101m" "\033[0;102m" "\033[0;103m" "\033[0;104m" "\033[0;105m" "\033[0;106m" "\033[0;107m" )
  8.     none="\033[0m" bold="\033[1m" dim="\033[2m" ital="\033[3m" ulin="\033[4m"
  9.     blnk="\033[5m" FIXME="\033[6m" rev="\033[7m" invs="\033[8m" strk="\033[9m"
  10.     #visbell="\033[?5h$(eval 'printf "\0" ~{0..'2000\})\033[?5l"
  11.     visbell(){ s="${1:-0.05s}"; printf "\033[?5h" >$(tty) && sleep "$s" && printf "\033[?5l" >$(tty); }
  12.     visbell="$(eval "printf \"%1.1s\" $'\a'{0..2000}" )"
  13.     # fkin horseshit...
  14.  
  15.  
  16.     #vi_ins_mode_string="\001\033[0;34m\033(0\002 m\001\033(B\033[0;37m\002-\001${host_prompt_color}\002)\001\033[0m\002"
  17.     vi_ins_mode_string="\001\033]4;7;#b3b0a6\007\033[0;34m\033(0\002 m\001\033(B\033[0;37m\002-\001${host_prompt_color}\002)\001\033[0m\002"
  18.     #vi_cmd_mode_string="\001\033[0;34m\033(0\002 m\001\033(B\033[0;37m\002!\001${host_prompt_color}\002]\001\033[0m\002"
  19.     #vi_cmd_mode_string="\001\033]4;7;#556876\007\e[4 q\033[0;34m\033(0\002 m\001\033(B\033[0;38;5;255m\002!\001${host_prompt_color}\002]\001\033[0m\002"
  20.     vi_cmd_mode_string="\001\033]4;7;#93a1a1\007\033[0;34m\033(0\002 m\001\033(B\033[0;38;5;255m\002!\001${host_prompt_color}\002]\001\033[0m\002"
  21.     #bind "set keyseq-timeout 240"
  22.     bind '"\M-^\C-^\C-e":vi-movement-mode'
  23.     bind -x '"\M-^\C-_\C-e":"visbell"'
  24.     bind '"\e":"\M-^\C-_\C-e\M-^\C-^\C-e"'
  25.     bind "set vi-ins-mode-string $(echo -e "$vi_ins_mode_string")"
  26.     bind "set vi-cmd-mode-string $(echo -e "$vi_cmd_mode_string")"
  27.     BASH_CMD_COUNT="1"
  28.  
  29.  
  30.     dbgtrap(){
  31.         # 1="${-//[^xv]/}"; to exlude other settings
  32.         #set +"$1"
  33.         #[[ "$1" =~ "x" ]] && printf "\033[3A\033[3M"
  34.         #[[ "$1" =~ "v" ]] && printf "\033[1A\033[1M"
  35.  
  36.         #extra="$(trap -p DEBUG)"
  37.         #extra="${extra#*\'}"
  38.         #extra="${extra%\'*}"
  39.         #trap ' printf "\033[0m\033[?7l\033[0m${extra}\r"; trap - DEBUG ' DEBUG
  40.         trap ' 999<&2 printf "\033[0m\033[?7l\033[0m\r" 2>&999; trap - DEBUG ' DEBUG
  41.     }
  42.  
  43.     tbar(){
  44.         #t="$(tty | cut -c 5-)"
  45.         t="$(tty)"
  46.         d="$(basename "$PWD")"
  47.         h="$(history 1|cut -d ' ' -f 3-)"
  48.         printf "\033]2;%s @ %s  --  %s\007" "${t:4}" "${d}" "${h}" #>/dev/tty
  49.         #printf "\033[K"
  50.     }
  51.  
  52.  
  53.     init(){
  54.         pipestatus=( "$@" )
  55.         history -a
  56.         export BASH_HIST_IDX="$(history 1|awk '{print $1}')"
  57.         export tstamp="$(/bin/date +%Y-%m-%d_%H:%M:%S_%s).$HOSTNAME"
  58.     }
  59.  
  60.     drawpipestat(){
  61.         local ec="${1%% :*}"
  62.         # Random words for inspiration :D
  63.         thesaurasuarus-rex(){ randword -w 3 ~/.bash/data/promptwords; }
  64.         # FFS just insert line with L.. no crazy jumpy crap with A B.
  65.         [[ "$ec" == "0" ]] \
  66.           && printf -- "\r   \033[0;94m%s\n" "$( thesaurasuarus-rex | tr '\n' '\t\t\t' )" \
  67.           && return
  68.         [[ "$ec" == "130" ]] \
  69.            && printf -- "\033L" \
  70.            || printf -- "%s\033[L  \033[1;34m%s" "$visbell" "$1"
  71.     }
  72.  
  73.     drawl(){
  74.         local lstat=""
  75.         local lstat="$(drawpipestat "${pipestatus[*]}")"
  76.         local ldate="$(date +%H:%M)"
  77.         local ltty="$host_identity_color$(tty|cut -c 5-)"
  78.         local lssh="$( [[ -n $SSH_CONNECTION ]] && printf " - $USER@$HOSTNAME")"
  79.         local ldir="$( case $PWD in ~/HWD) printf "HWD";; ~) printf "~";; *) printf "$PWD";; esac )"
  80.  
  81.         local data=( "${lstat}" "\n "
  82.            "${fg[4]}" "${smacs}" "l" "${rmacs}" "[" "${fg[6]}" "${ldate}"
  83.            "${fg[4]}" "]" "${smacs}" "q" "${rmacs}" "[" "${ltty}" "${lssh}"
  84.            "${fg[4]}" "]" "${smacs}" "qqq" "${rmacs}" "[" "${fg[2]}" "${ldir}"
  85.            "${fg[4]}" "]"
  86.         )
  87.  
  88.         printf "%b" "${data[@]}"
  89.     }
  90.  
  91.     drawr(){
  92.         ((${COLUMNS}0)) || return
  93.         local rstat=""
  94.         ((${pipestatus[0]}0<1)) || { \
  95.             local rstat=( "\033[8D" "${fg[4]}" "[" "${fg[9]}" "${blnk}" )
  96.                   rstat+=( "$(printf "% 3.3s" "$pipestatus")" )
  97.                   rstat+=( "${none}" "${fg[4]}" "]" "${smacs}" "qqq" "${rmacs}" )
  98.         }
  99.         local rpad="\r\033[$(($COLUMNS-13))C"
  100.         local rcmdn="$(printf "% 2.2s" "$BASH_CMD_COUNT")"
  101.         local rhistn="$(printf "% 4.4s" "$BASH_HIST_IDX")"
  102.         local rendc="$(printf "\xe2\x95\x90\xe2\x95\xa1\x0a")"
  103.  
  104.         local data=( "${rpad}" "${rstat[@]}"
  105.             "${fg[4]}" "[" "${fg[8]}" "${rcmdn}"
  106.             "${fg[4]}" "]" "${smacs}" "q" "${rmacs}"
  107.             "${fg[4]}" "[" "${fg[8]}" "${rhistn}"
  108.             "${fg[4]}" "]═╡" # "${smacs}" "${rendc}" "${rmacs}"
  109.         )
  110.  
  111.         printf "%b" "${data[@]}"
  112.     }
  113.  
  114.     histmaster(){
  115.       local histfile
  116.       histfile="$HOME/.bash/data/HistMaster/histmaster"
  117.       history 1 | awk -v t="$(date +%s)" -v d="$(pwd)" '
  118.         {$1=""; printf("\n- cmd:%s\n\twhen: %s\n\twhere: %s\n", $0, t, d)}' >> "$histfile"
  119.       return $?
  120.     }
  121.  
  122.     unsetxv(){
  123.         # 1="${-//[^xv]/}"; to exlude other settings
  124.         set +"$1"
  125.         [[ "$1" =~ "x" ]] && printf "\033[3A\033[3M"
  126.         [[ "$1" =~ "v" ]] && printf "\033[1A\033[1M"
  127.     }
  128.  
  129.     promptcmd(){
  130.         unsetxv "${-//[^xv]/}"
  131.         #dbgtrap "${-//[^xv]/}"
  132.         # why were in the hole. might as well dig
  133.  
  134.         # DROP DAH BASSS
  135.         [[ "${1#*:}" =~ (0|130) ]] \
  136.           && printf "\033[%sB" "${LINES}" \
  137.           || printf "\033[%sB" "$((LINES-${#3}))"
  138.         init "$@"
  139.         drawl
  140.         drawr
  141.         printf "\n"
  142.         tbar
  143.  
  144.         let BASH_CMD_COUNT++
  145.         #export PS1="\[\0337\033[?7h\$(promptcmd "$?" ":" "${PIPESTATUS[@]}")\] \[\033[0;37m\]"
  146.         export PS1="\[\0337\033[?7h\$(histmaster)\] \[\033[0;37m\]"
  147.         export PROMPT_COMMAND='promptcmd "$?" ":" "${PIPESTATUS[@]}";'
  148.        
  149.         silentprint(){
  150.           printf -- "\033[M%s\033[B\033[L" "$@"
  151.         }
  152.         tog(){
  153.           [[ "${-/[isl]/}" =~ "$1" ]] \
  154.             && set "+$s" && return 1 \
  155.             || set "-$s"
  156.         }
  157.         dbgprint(){
  158.           tog xv
  159.           ! (("$?"==0)) \
  160.             && printf -- "\033[0m\033[?7l\033[B\033[L" \
  161.             || printf -- "\033[?7l\033[%sB" "$LINES"
  162.         }
  163.        
  164.         #trap ' printf -- "\033[A\033[L\033[0m\033[?7l\033[M\033[B" ' DEBUG
  165.         #trap ' dbgprint ' DEBUG
  166.         trap ' eval printf "\\\033[$((LINES-6))A" >&2 ' ERR
  167.         # NOTE: 3 lines. Draw the pretty vi style ~ on the left. using 3 this time to clean up signit
  168.         trap ' eval '\''printf "\\n\\033[0m\\033[J\\033[34m%.1s\\033[0m\\033[?7l" ~{3..'\''$LINES\}; tput cup 2 0 ' INT
  169.     }
  170.  
  171.  
  172.     # Reallyyy wants to be a string instead of func...
  173.     ### A good place to `set +x`? or atleast bail on `promptcmd`
  174.     IFS=$':' read -r -a PS4_TRAP <<<" \
  175.         for once; do : \
  176.           [[ \"$BASH_SUBSHELL\" == \"promptcmd\" ]] && break; : \
  177.           trap 'printf \"\033[38;5;248m\" >&2 ' DEBUG; : \
  178.           printf \"\033[91m\r$BASH_SUBSHELL\033[36m\" >&2; : \
  179.         done; : \
  180.         printf \"\033[0;36m\"; : \
  181.         "
  182.     export PS4_TRAP
  183.  
  184.  
  185.     # NOTE: 4 lines. the actual length we should move.
  186.     #export PS0='$(HistMaster)$(eval '\''printf "\\n\\033[0m\\033[J\\033[34m%.1s\\033[0m\\033[?7l" ~{4..'\''$LINES\}; tput cup 2 0 )$(tbar)'
  187.     export PS0='$(eval '\''printf "\\n\\033[0m\\033[J\\033[34m%.1s\\033[0m\\033[?7l" ~{4..'\''$LINES\}; tput cup 2 0 )$(tbar)'
  188.     export PS1="\[\0337\033[?7h\$(HistMaster)\] \[\033[0;37m\]"
  189.     export PROMPT_COMMAND='promptcmd "$?" ":" "${PIPESTATUS[@]}"'
  190.     export PS2=" \[\e[0;34\]m└──\[$host_prompt_color\]\\\\ \[\033[1;37m\]"
  191.     #export PS4=$'+ \0337$(prompt4)'
  192.     export PS4=$'>\0337\033[0;31m~$?\033[0;91m:$(eval ${PS4_TRAP[@]}) '
  193.     export smPS4=$'+\0337'"$( eval printf "\\\\033[31m%.1s" +'{1..'${BASH_SUBSHELL}\} )"
  194.     #export PS4="+7"$'$(printf "\r\033[31m+++++++8"; printf "\033[0;36m"  )'
  195.     #export PS4="+7"$'$(read -p $'\''\x1b[6n'\'' -d R cpos; printf "\r\033[31m" +'\''{0..'\''$cpos\}8"; printf "\033[0m"  )'
  196.  
  197. }
captcha