Comments (4)
from here: https://starship.rs/faq/#the-docs-say-starship-is-cross-shell-why-isn-t-my-preferred-shell-supported
this gets things going:
# Get the status code from the last command executed
STATUS=$?
# Get the number of jobs running.
NUM_JOBS=$(jobs -p | wc -l)
# Set the prompt to the output of `starship prompt`
PS1="$(starship prompt --status=$STATUS --jobs=$NUM_JOBS)"
sortof
~
❯ echo $PWD
/home/nvp/Development/NullVoxPopuli/dotfiles # not ~
which probably makes sense as the starship prompt
command is likely meant to be invoked every time the PS1 is rendered.
Going back to the init script tho, this is the script that's output to eval
after the version branching:
❯ /home/nvp/.cargo/bin/starship init bash --print-full-init
# We use PROMPT_COMMAND and the DEBUG trap to generate timing information. We try
# to avoid clobbering what we can, and try to give the user ways around our
# clobbers, if it's unavoidable. For example, PROMPT_COMMAND is appended to,
# and the DEBUG trap is layered with other traps, if it exists.
# A bash quirk is that the DEBUG trap is fired every time a command runs, even
# if it's later on in the pipeline. If uncorrected, this could cause bad timing
# data for commands like `slow | slow | fast`, since the timer starts at the start
# of the "fast" command.
# To solve this, we set a flag `STARSHIP_PREEXEC_READY` when the prompt is
# drawn, and only start the timer if this flag is present. That way, timing is
# for the entire command, and not just a portion of it.
# A way to set '$?', since bash does not allow assigning to '$?' directly
function _starship_set_return() { return "${1:-0}"; }
# Will be run before *every* command (even ones in pipes!)
starship_preexec() {
# Save previous command's last argument, otherwise it will be set to "starship_preexec"
local PREV_LAST_ARG=$1
# Avoid restarting the timer for commands in the same pipeline
if [ "${STARSHIP_PREEXEC_READY:-}" = "true" ]; then
STARSHIP_PREEXEC_READY=false
STARSHIP_START_TIME=$(/home/nvp/.cargo/bin/starship time)
fi
: "$PREV_LAST_ARG"
}
# Will be run before the prompt is drawn
starship_precmd() {
# Save the status, because commands in this pipeline will change $?
STARSHIP_CMD_STATUS=$? STARSHIP_PIPE_STATUS=(${PIPESTATUS[@]})
if [[ "${#BP_PIPESTATUS[@]}" -gt "${#STARSHIP_PIPE_STATUS[@]}" ]]; then
STARSHIP_PIPE_STATUS=(${BP_PIPESTATUS[@]})
fi
# Due to a bug in certain Bash versions, any external process launched
# inside $PROMPT_COMMAND will be reported by `jobs` as a background job:
#
# [1] 42135 Done /bin/echo
#
# This is a workaround - we run `jobs` once to clear out any completed jobs
# first, and then we run it again and count the number of jobs.
#
# More context: https://github.com/starship/starship/issues/5159
# Original bug: https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00117.html
jobs &>/dev/null
local NUM_JOBS=0
# Evaluate the number of jobs before running the preserved prompt command, so that tools
# like z/autojump, which background certain jobs, do not cause spurious background jobs
# to be displayed by starship. Also avoids forking to run `wc`, slightly improving perf.
for job in $(jobs -p); do [[ $job ]] && ((NUM_JOBS++)); done
# Run the bash precmd function, if it's set. If not set, evaluates to no-op
"${starship_precmd_user_func-:}"
# Set $? to the preserved value before running additional parts of the prompt
# command pipeline, which may rely on it.
_starship_set_return "$STARSHIP_CMD_STATUS"
eval "$_PRESERVED_PROMPT_COMMAND"
# Prepare the timer data, if needed.
if [[ $STARSHIP_START_TIME ]]; then
STARSHIP_END_TIME=$(/home/nvp/.cargo/bin/starship time)
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
PS1="$(/home/nvp/.cargo/bin/starship prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS" --cmd-duration=$STARSHIP_DURATION)"
unset STARSHIP_START_TIME
else
PS1="$(/home/nvp/.cargo/bin/starship prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS")"
fi
STARSHIP_PREEXEC_READY=true # Signal that we can safely restart the timer
}
# If the user appears to be using https://github.com/rcaloras/bash-preexec,
# then hook our functions into their framework.
if [[ "${__bp_imported:-}" == "defined" || $preexec_functions || $precmd_functions ]]; then
# bash-preexec needs a single function--wrap the args into a closure and pass
starship_preexec_all(){ starship_preexec "$_"; }
preexec_functions+=(starship_preexec_all)
precmd_functions+=(starship_precmd)
else
# We want to avoid destroying an existing DEBUG hook. If we detect one, create
# a new function that runs both the existing function AND our function, then
# re-trap DEBUG to use this new function. This prevents a trap clobber.
dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
if [[ -z "$dbg_trap" ]]; then
trap 'starship_preexec "$_"' DEBUG
elif [[ "$dbg_trap" != 'starship_preexec "$_"' && "$dbg_trap" != 'starship_preexec_all "$_"' ]]; then
starship_preexec_all() {
local PREV_LAST_ARG=$1 ; $dbg_trap; starship_preexec; : "$PREV_LAST_ARG";
}
trap 'starship_preexec_all "$_"' DEBUG
fi
# Finally, prepare the precmd function and set up the start time. We will avoid to
# add multiple instances of the starship function and keep other user functions if any.
if [[ -z "$PROMPT_COMMAND" ]]; then
PROMPT_COMMAND="starship_precmd"
elif [[ "$PROMPT_COMMAND" != *"starship_precmd"* ]]; then
# Appending to PROMPT_COMMAND breaks exit status ($?) checking.
# Prepending to PROMPT_COMMAND breaks "command duration" module.
# So, we are preserving the existing PROMPT_COMMAND
# which will be executed later in the starship_precmd function
_PRESERVED_PROMPT_COMMAND="$PROMPT_COMMAND"
PROMPT_COMMAND="starship_precmd"
fi
fi
# Ensure that $COLUMNS gets set
shopt -s checkwinsize
# Set up the start time and STARSHIP_SHELL, which controls shell-specific sequences
STARSHIP_START_TIME=$(/home/nvp/.cargo/bin/starship time)
export STARSHIP_SHELL="bash"
# Set up the session key that will be used to store logs
STARSHIP_SESSION_KEY="$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM"; # Random generates a number b/w 0 - 32767
STARSHIP_SESSION_KEY="${STARSHIP_SESSION_KEY}0000000000000000" # Pad it to 16+ chars.
export STARSHIP_SESSION_KEY=${STARSHIP_SESSION_KEY:0:16}; # Trim to 16-digits if excess.
# Set the continuation prompt
PS2="$(/home/nvp/.cargo/bin/starship prompt --continuation)"
I notice there is a setting of PS2, which isn't PS1, which gives me pause.
from starship.
I suppose I can ignore the PS2 because I found the PS1 here:
# Prepare the timer data, if needed.
if [[ $STARSHIP_START_TIME ]]; then
STARSHIP_END_TIME=$(/home/nvp/.cargo/bin/starship time)
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
PS1="$(/home/nvp/.cargo/bin/starship prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS" --cmd-duration=$STARSHIP_DURATION)"
unset STARSHIP_START_TIME
else
PS1="$(/home/nvp/.cargo/bin/starship prompt --terminal-width="$COLUMNS" --status=$STARSHIP_CMD_STATUS --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="$NUM_JOBS")"
fi
and if I just manually copy that PS1 line, my terminal updates appropriately (if I re-run the PS1= line after every command, manually).
from starship.
I see that all if this is fueled by PROMPT_COMMAND
, which mine is currently wrong:
❯ echo $PROMPT_COMMAND
echo -ne "\033]0;$(basename ${PWD})\007"
from starship.
ah-ha! I fixed it!
I had this in my series of bash_profile scripts:
export PROMPT_COMMAND='echo -ne "\033]0;$(basename ${PWD})\007"'
# and then later:
# If this is an xterm set the title to user@host:dir
# http://askubuntu.com/questions/126737/make-gnome-terminal-show-the-command-running-as-title
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
# Show the currently running command in the terminal title:
# http://www.davidpashley.com/articles/xterm-titles-with-bash.html
show_command_in_title_bar()
{
case "$BASH_COMMAND" in
*\033]0*)
# The command is trying to set the title bar as well;
# this is most likely the execution of $PROMPT_COMMAND.
# In any case nested escapes confuse the terminal, so don't
# output them.
;;
*)
echo -ne "\033]0;${USER}@${HOSTNAME}: ${BASH_COMMAND}\007"
;;
esac
}
trap show_command_in_title_bar DEBUG
;;
*)
;;
esac
Which, after removing both I have the starship prompt back. 🥳
So it seems maybe something maybe changed in starship to not override an already set PROMPT_COMMAND
? idk.
Anywho, I'm back in business. 🎉
from starship.
Related Issues (20)
- Questionable prompt behaviour when both bun and node are installed HOT 5
- Release for s390x architecture
- Config for disabling conda simply doesn't work HOT 1
- AWS disabled not work HOT 2
- Allow to globally customize section prefix or suffix HOT 3
- binary size massively increased for aarch64 HOT 1
- `starship init bash` in vscode: integrated terminal crashes due to infinite loop HOT 1
- Command Duration: Show decimals for seconds instead of rendering millis separately HOT 1
- Make `render_time` format more consistent
- Override settings for specific shell HOT 1
- OS - Add ArcoLinux HOT 1
- `cmd_duration`: Introduce Variables
- issue with custom format: unable to remove <username>@<hostname> HOT 2
- [Windows] (starship::config): Failed to load config value: Error in 'StarshipRoot' at 'os': Unknown key HOT 6
- Requesting the build for x86_64-pc-windows-msvc HOT 2
- Starship only shows up from second prompt onwards HOT 3
- Python Logo showing empty icon HOT 1
- Starship Not working HOT 16
- `PROMPT_MULTILINE_INDICATOR` prompt has incorrect formatting in nushell
- Reverse-search in bash leads to wrong cursor positioning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from starship.