get_git_branch() {
out=$(git branch --show-current 2> /dev/null)
if [[ $? -eq 0 ]]; then
printf "(%s) " "$out"
fi
}
export PS1="\$(get_git_branch)\u@\h [\W]\[$(tput sgr0)\] >"
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
type sed
git branch 2> /dev/null | /usr/bin/sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
pacman -Qs sed
localectl
locale
locale -a
So what does that command display when it isn't a git repo?
in fact I added a `() ` and it will display
(master) [username @ hostname ] $
when it is a git repo
and it will display
() [username @ hostname ] $
when it isn't a git repo and I do not want the empty brackets
]]>OK I know. change it to:
export PS1="\$(git branch --show-current 2> /dev/null)\[$(tput sgr0)\]"
but I want it display nothing when this is not a git repo.
So what does that command display when it isn't a git repo?
]]>What is the output of `git branch` in CWD?
I said in the first post. It is `master`
]]>export PS1="\$(git branch --show-current 2> /dev/null)\[$(tput sgr0)\]"
but I want it display nothing when this is not a git repo.
]]>git branch --show-current 2>/dev/null
and its PS1 to get git branch is:
export PS1="\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\[$(tput sgr0)\]"
but it cannot get git branch and display only `()`
()git branch 2>/dev/null
master
()