my same-dir transient #229
gas
started this conversation in
Show and tell
Replies: 1 comment
-
I've made a version 2 using that better elapsed function for execution time on the right prompt, and gets erased by a blank rps1_transient for a cleaner screen. # blerc transient v2
# included \u codes for installed nerd-font https://gitee.com/bearxup/nerd-fonts#features
# Trying to achieve same-dir transient prompt as p10k on zsh (full prompt on changedir but just once)
# my prompt, starting with \n
PS1="\n\e[01;33m\u\e[00m \e[01;35m[\w]\e[00m "$'\uf460 '
# or cleaner PS1="\n\e[01;33m\u\e[00m "$'\uf460 '
# prompt for changed dir
TIMEPS1='\e[01;35m'$'\uf413'' [\w]\e[00m \e[38;2;150;150;150m'$'\uf43a'' \t \n'
# new
bleopt prompt_ps1_final=$'\e[01;33m'$'\uf460 ' # maybe do not \n here
bleopt exec_errexit_mark=''
bleopt prompt_eol_mark=''
bleopt prompt_ps1_transient=same-dir
ble-import contrib/prompt-elapsed
# status bar
bleopt prompt_status_align=$'justify=*'
ble-face prompt_status_line='fg=229,bg=67'
bleopt prompt_status_line='[\w] *-\$-*'$'\uf490''\s \V*[\q{row}:\q{column}]*\d'
# pre exec set
my-preexec() {
last_prompt=1
}
blehook PREEXEC=my-preexec
# post exec set
my-postexec() {
local exit=$?
if ((exit==0)); then
my_error=0
else
my_error=1
fi
}
blehook POSTEXEC=my-postexec
# get this
my-changedir() {
last_prompt=2
}
blehook CHPWD=my-changedir
my-precmd() {
local NEWDIRPS1=$TIMEPS1
# color for error
case "${my_error}" in
1) elapsed_color=$'\e[31m \uf497'
;;
0) elapsed_color=$'\x1b[32m \uf496'
;;
esac
# don't know if 1|2) then 2) would work so repeating things...
case "${last_prompt}" in
1) #printf '\command!'
# sleep 1
bleopt prompt_rps1=$'${elapsed_color} \q{contrib/elapsed}'
bleopt prompt_rps1_final=' ' #1 space here for substitution
;;
2) #printf '\dir changed!'
# sleep 1
bleopt prompt_rps1=$'${elapsed_color} \q{contrib/elapsed}'
bleopt prompt_rps1_final=' '
printf "${NEWDIRPS1@P}"
simple-ruler '\x1b[35m·'
;;
*) #printf '\-empty!'
# sleep 1
bleopt prompt_rps1=
bleopt prompt_rps1_final=
;;
esac
unset my_error
unset last_prompt
}
blehook PRECMD=my-precmd
simple-ruler() {
case $1 in
"") echo " "$(seq $(($(($(tput cols)))/2))) | sed 's/ [1234567890]*/ ·/g;' ;;
*) echo " "$(seq $(($(($(tput cols)))/2))) | sed 's/ [1234567890]*/ '"$1"'/g;' ;;
esac
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, first I want to say thank you for ble.sh. It is fantastic.
Though I couldn't get the transient "same-dir" functionality that I wanted.
I tried setting same-dir, trim, ruler, etc, but I just wanted a full prompt+ruler just once, not all the time, so I ended making this .blerc
It's a bit basic (I am learning bash btw) but it works.
Edit: Well I've found that contrib/elapsed function a bit late lol, though this one served to me with ble_hoooks :)
Beta Was this translation helpful? Give feedback.
All reactions