Hallo Leute!
Hat einer von euch eine Idee warum sich das “$” verschwindet wenn ich den eingegeben Befehl lösche? Das sieht bei mir in etwa so aus:
Und ist die Funktion:
set_prompt () {
Last_Command=$?
PS1="$white\$? "
if [[ $Last_Command == 0 ]]; then
PS1+="$green$checkmark "
else
PS1+="$red$fancyx "
fi
PS1+="($timer_show) \t "
if [[ $EUID == 0 ]]; then
PS1+="$red\\u$green@\\h "
else
PS1+="$yellow\\u@\\h "
fi
PS1+="$reset\w\n"
PS1+="$(git_color)"
PS1+="$(git_branch)"
PS1+="$blue\$ $reset"
}
red="\033[0;31m"
yellow="\033[1;33m"
cyan="\033[0;36m"
green="\033[0;32m"
ochre="\033[38;5;95m"
blue="\033[1;34m"
white="\033[0;37m"
reset="\033[0m"
fancyx='\342\234\227'
checkmark='\342\234\223'
##################
### GIT STATUS ###
##################
function git_color {
local git_status="$(git status 2> /dev/null)"
if [[ $git_status =~ "Sobald Ihr Arbeitsverzeichnis unverändert ist" ]]; then
echo -e $red
elif [[ $git_status =~ "Ihr Branch ist Commit vor" ]]; then
echo -e $yellow
elif [[ $git_status =~ "nichts zu committen" ]]; then
echo -e $green
else
echo -e $ochre
fi
}
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="Auf Branch ([^${IFS}]*)"
local on_commit="HEAD losgelöst bei ([^${IFS}]*)"
if [[ $git_status =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
echo "($branch)"
elif [[ $git_status =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
echo "($commit)"
fi
}
#############
### TIMER ###
#############
function timer_now {
date +%s%N
}
function timer_start {
timer_start=${timer_start:-$(timer_now)}
}
function timer_stop {
local delta_us=$((($(timer_now) - $timer_start) / 1000))
local us=$((delta_us % 1000))
local ms=$(((delta_us / 1000) % 1000))
local s=$(((delta_us / 1000000) % 60))
local m=$(((delta_us / 60000000) % 60))
local h=$((delta_us / 3600000000))
# Goal: always show around 3 digits of accuracy
if ((h > 0)); then timer_show=${h}${m}m
elif ((m > 0)); then timer_show=${m}m${s}s
elif ((s >= 10)); then timer_show=${s}.$((ms / 100))s
elif ((s > 0)); then timer_show=${s}.$(printf %03d $ms)s
elif ((ms >= 100)); then timer_show=${ms}ms
elif ((ms > 0)); then timer_show=${ms}.$((us / 100))ms
else timer_show=${us}us
fi
unset timer_start
}
PROMPT_COMMAND='set_prompt'
Ich wollte die PS1 ein wenig funktionaler gestalten, aber dass das “$” sich immer wieder löscht finde ich schon merkwürdig.
Ist es ein Problem mit Bash oder mit dem Skript? Hat jemand eine Ahnung?
Danke