ZSH Theme not updating from functionHow to remove local (untracked) files from the current Git working tree?Remove a file from a Git repository without deleting it from the local filesystemDelete commits from a branch in GitHow can I delete a file from git repo?Branch from a previous commit using GitHow can I determine the URL that a local Git repository was originally cloned from?How to compare files from two different branches?How do I update a GitHub forked repository?How to copy a folder from remote to local using scp?Remove files from Git commit
Could an aircraft fly or hover using only jets of compressed air?
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
Watching something be written to a file live with tail
Cross compiling for RPi - error while loading shared libraries
Is it unprofessional to ask if a job posting on GlassDoor is real?
meaning of に in 本当に?
Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
What does the "remote control" for a QF-4 look like?
Modeling an IP Address
Is it inappropriate for a student to attend their mentor's dissertation defense?
Horror movie about a virus at the prom; beginning and end are stylized as a cartoon
Can a vampire attack twice with their claws using Multiattack?
What typically incentivizes a professor to change jobs to a lower ranking university?
Why can't I see bouncing of a switch on an oscilloscope?
How can bays and straits be determined in a procedurally generated map?
Does detail obscure or enhance action?
"You are your self first supporter", a more proper way to say it
What does "Puller Prush Person" mean?
Paid for article while in US on F-1 visa?
What defenses are there against being summoned by the Gate spell?
Why do I get two different answers for this counting problem?
DC-DC converter from low voltage at high current, to high voltage at low current
Why can't we play rap on piano?
ZSH Theme not updating from function
How to remove local (untracked) files from the current Git working tree?Remove a file from a Git repository without deleting it from the local filesystemDelete commits from a branch in GitHow can I delete a file from git repo?Branch from a previous commit using GitHow can I determine the URL that a local Git repository was originally cloned from?How to compare files from two different branches?How do I update a GitHub forked repository?How to copy a folder from remote to local using scp?Remove files from Git commit
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to write a ZSH Theme that displays specific characters depending on the Git status (if within a git repo). I've previously implemented this theme in Bash, but am having some issues with moving over to ZSH. This is likely my own fault, but if anyone could help it'd be much appreciated.
Relevant Portion of my theme:
local jobs="%$terminfo[bold]$fg[cyan]%[%$fg[magenta]%%j%$terminfo[bold]$fg[cyan]%]%$reset_color%"
local git_branch='$(git_prompt_info)%$reset_color%'
local current_dir="%$terminfo[bold]$fg[orange]%%~%$reset_color%"
if [[ $UID -eq 0 ]]; then
local user_host="%$terminfo[bold]$fg[red]%%n@%m%$reset_color%"
local user_symbol="#"
else
local user_host="%$terminfo[bold]$fg[green]%%n@%$fg[red]%%m%$reset_color%"
local user_symbol="$"
fi
function git_has_unstaged()
if ! $(git diff-files --quiet --ignore-submodules --); then
echo -n "%*! ";
fi;
function git_has_uncommitted()
if [ ! $(git diff --quiet --ignore-submodules --cached; echo "$?") = "0" ]; then
echo -n "%*+ ";
fi;
function git_has_untracked()
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo -n "%*? ";
fi;
function git_has_stashed()
if $(git rev-parse --verify refs/stash &>/dev/null); then
echo -n "%*$ ";
fi;
function git_status_symbols()
echo -n "%$terminfo[bold]$fg[blue]%[";
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "$?") = "0" ]; then
#Now is it Git repo
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" = "false" ]; then
# check if the current directory is in .git before running git checks
# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null;
git_has_uncommitted;
git_has_unstaged;
git_has_untracked;
git_has_stashed;
fi;
fi;
echo -n "]%$reset_color%";
PROMPT="╭─$user_host $current_dir $jobs $git_branch $(git_status_symbols)
╰─%B$user_symbol%b "
ZSH_THEME_GIT_PROMPT_PREFIX="%$fg[yellow]%‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="›%$reset_color%"
My issue is that the git_status_symbols value in the prompt doesn't update according to updates in the fs/git. Example:
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git status
On branch bored
Your branch is up to date with 'origin/bored'.
nothing to commit, working tree clean
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ touch ./t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git_has_untracked
%*? % ╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:50:37? ]
╰─$
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:14? ]
╰─$ rm t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:16? ]
╰─$ git_has_untracked
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:22? ]
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$
As you can see, while my git_has_untracked
function is properly echoing a ?, the prompt is not reflecting this until I start a new shell. After removing the untracked file, the git_has_untracked
function properly no longer echoes anything. What's interesting here is that the time is still being updated. Upon creation of a new shell the prompt is once again correct.
Any help appreciated! Thanks
git shell themes zsh
add a comment |
I'm trying to write a ZSH Theme that displays specific characters depending on the Git status (if within a git repo). I've previously implemented this theme in Bash, but am having some issues with moving over to ZSH. This is likely my own fault, but if anyone could help it'd be much appreciated.
Relevant Portion of my theme:
local jobs="%$terminfo[bold]$fg[cyan]%[%$fg[magenta]%%j%$terminfo[bold]$fg[cyan]%]%$reset_color%"
local git_branch='$(git_prompt_info)%$reset_color%'
local current_dir="%$terminfo[bold]$fg[orange]%%~%$reset_color%"
if [[ $UID -eq 0 ]]; then
local user_host="%$terminfo[bold]$fg[red]%%n@%m%$reset_color%"
local user_symbol="#"
else
local user_host="%$terminfo[bold]$fg[green]%%n@%$fg[red]%%m%$reset_color%"
local user_symbol="$"
fi
function git_has_unstaged()
if ! $(git diff-files --quiet --ignore-submodules --); then
echo -n "%*! ";
fi;
function git_has_uncommitted()
if [ ! $(git diff --quiet --ignore-submodules --cached; echo "$?") = "0" ]; then
echo -n "%*+ ";
fi;
function git_has_untracked()
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo -n "%*? ";
fi;
function git_has_stashed()
if $(git rev-parse --verify refs/stash &>/dev/null); then
echo -n "%*$ ";
fi;
function git_status_symbols()
echo -n "%$terminfo[bold]$fg[blue]%[";
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "$?") = "0" ]; then
#Now is it Git repo
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" = "false" ]; then
# check if the current directory is in .git before running git checks
# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null;
git_has_uncommitted;
git_has_unstaged;
git_has_untracked;
git_has_stashed;
fi;
fi;
echo -n "]%$reset_color%";
PROMPT="╭─$user_host $current_dir $jobs $git_branch $(git_status_symbols)
╰─%B$user_symbol%b "
ZSH_THEME_GIT_PROMPT_PREFIX="%$fg[yellow]%‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="›%$reset_color%"
My issue is that the git_status_symbols value in the prompt doesn't update according to updates in the fs/git. Example:
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git status
On branch bored
Your branch is up to date with 'origin/bored'.
nothing to commit, working tree clean
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ touch ./t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git_has_untracked
%*? % ╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:50:37? ]
╰─$
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:14? ]
╰─$ rm t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:16? ]
╰─$ git_has_untracked
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:22? ]
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$
As you can see, while my git_has_untracked
function is properly echoing a ?, the prompt is not reflecting this until I start a new shell. After removing the untracked file, the git_has_untracked
function properly no longer echoes anything. What's interesting here is that the time is still being updated. Upon creation of a new shell the prompt is once again correct.
Any help appreciated! Thanks
git shell themes zsh
add a comment |
I'm trying to write a ZSH Theme that displays specific characters depending on the Git status (if within a git repo). I've previously implemented this theme in Bash, but am having some issues with moving over to ZSH. This is likely my own fault, but if anyone could help it'd be much appreciated.
Relevant Portion of my theme:
local jobs="%$terminfo[bold]$fg[cyan]%[%$fg[magenta]%%j%$terminfo[bold]$fg[cyan]%]%$reset_color%"
local git_branch='$(git_prompt_info)%$reset_color%'
local current_dir="%$terminfo[bold]$fg[orange]%%~%$reset_color%"
if [[ $UID -eq 0 ]]; then
local user_host="%$terminfo[bold]$fg[red]%%n@%m%$reset_color%"
local user_symbol="#"
else
local user_host="%$terminfo[bold]$fg[green]%%n@%$fg[red]%%m%$reset_color%"
local user_symbol="$"
fi
function git_has_unstaged()
if ! $(git diff-files --quiet --ignore-submodules --); then
echo -n "%*! ";
fi;
function git_has_uncommitted()
if [ ! $(git diff --quiet --ignore-submodules --cached; echo "$?") = "0" ]; then
echo -n "%*+ ";
fi;
function git_has_untracked()
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo -n "%*? ";
fi;
function git_has_stashed()
if $(git rev-parse --verify refs/stash &>/dev/null); then
echo -n "%*$ ";
fi;
function git_status_symbols()
echo -n "%$terminfo[bold]$fg[blue]%[";
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "$?") = "0" ]; then
#Now is it Git repo
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" = "false" ]; then
# check if the current directory is in .git before running git checks
# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null;
git_has_uncommitted;
git_has_unstaged;
git_has_untracked;
git_has_stashed;
fi;
fi;
echo -n "]%$reset_color%";
PROMPT="╭─$user_host $current_dir $jobs $git_branch $(git_status_symbols)
╰─%B$user_symbol%b "
ZSH_THEME_GIT_PROMPT_PREFIX="%$fg[yellow]%‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="›%$reset_color%"
My issue is that the git_status_symbols value in the prompt doesn't update according to updates in the fs/git. Example:
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git status
On branch bored
Your branch is up to date with 'origin/bored'.
nothing to commit, working tree clean
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ touch ./t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git_has_untracked
%*? % ╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:50:37? ]
╰─$
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:14? ]
╰─$ rm t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:16? ]
╰─$ git_has_untracked
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:22? ]
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$
As you can see, while my git_has_untracked
function is properly echoing a ?, the prompt is not reflecting this until I start a new shell. After removing the untracked file, the git_has_untracked
function properly no longer echoes anything. What's interesting here is that the time is still being updated. Upon creation of a new shell the prompt is once again correct.
Any help appreciated! Thanks
git shell themes zsh
I'm trying to write a ZSH Theme that displays specific characters depending on the Git status (if within a git repo). I've previously implemented this theme in Bash, but am having some issues with moving over to ZSH. This is likely my own fault, but if anyone could help it'd be much appreciated.
Relevant Portion of my theme:
local jobs="%$terminfo[bold]$fg[cyan]%[%$fg[magenta]%%j%$terminfo[bold]$fg[cyan]%]%$reset_color%"
local git_branch='$(git_prompt_info)%$reset_color%'
local current_dir="%$terminfo[bold]$fg[orange]%%~%$reset_color%"
if [[ $UID -eq 0 ]]; then
local user_host="%$terminfo[bold]$fg[red]%%n@%m%$reset_color%"
local user_symbol="#"
else
local user_host="%$terminfo[bold]$fg[green]%%n@%$fg[red]%%m%$reset_color%"
local user_symbol="$"
fi
function git_has_unstaged()
if ! $(git diff-files --quiet --ignore-submodules --); then
echo -n "%*! ";
fi;
function git_has_uncommitted()
if [ ! $(git diff --quiet --ignore-submodules --cached; echo "$?") = "0" ]; then
echo -n "%*+ ";
fi;
function git_has_untracked()
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo -n "%*? ";
fi;
function git_has_stashed()
if $(git rev-parse --verify refs/stash &>/dev/null); then
echo -n "%*$ ";
fi;
function git_status_symbols()
echo -n "%$terminfo[bold]$fg[blue]%[";
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "$?") = "0" ]; then
#Now is it Git repo
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" = "false" ]; then
# check if the current directory is in .git before running git checks
# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null;
git_has_uncommitted;
git_has_unstaged;
git_has_untracked;
git_has_stashed;
fi;
fi;
echo -n "]%$reset_color%";
PROMPT="╭─$user_host $current_dir $jobs $git_branch $(git_status_symbols)
╰─%B$user_symbol%b "
ZSH_THEME_GIT_PROMPT_PREFIX="%$fg[yellow]%‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="›%$reset_color%"
My issue is that the git_status_symbols value in the prompt doesn't update according to updates in the fs/git. Example:
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git status
On branch bored
Your branch is up to date with 'origin/bored'.
nothing to commit, working tree clean
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ touch ./t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ git_has_untracked
%*? % ╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:50:37? ]
╰─$
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:14? ]
╰─$ rm t
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:16? ]
╰─$ git_has_untracked
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› [1:52:22? ]
╰─$ zsh
╭─theonlyjohnny@phoenix ~/configs [0] ‹bored› []
╰─$
As you can see, while my git_has_untracked
function is properly echoing a ?, the prompt is not reflecting this until I start a new shell. After removing the untracked file, the git_has_untracked
function properly no longer echoes anything. What's interesting here is that the time is still being updated. Upon creation of a new shell the prompt is once again correct.
Any help appreciated! Thanks
git shell themes zsh
git shell themes zsh
asked Mar 8 at 1:56
theonlyjohnnytheonlyjohnny
155
155
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This is happening because your PROMPT
variable contains the command substitution $(git_status_symbols)
. This evaluation happens once during assignment and not on every expansion of PROMPT
.
The easiest way to fix this is by using a precmd
that fills the psvar
array and then insert that value into the prompt with a form of %v
. For example:
precmd () psvar[1]=$(git_status_symbols);
PROMPT="╭─$user_host $current_dir $jobs $git_branch %1v
╰─%B$user_symbol%b "
Also, be aware that zsh has its own vcs support (for Git and others) which you may or may not want to leverage instead of writing custom code.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055662%2fzsh-theme-not-updating-from-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is happening because your PROMPT
variable contains the command substitution $(git_status_symbols)
. This evaluation happens once during assignment and not on every expansion of PROMPT
.
The easiest way to fix this is by using a precmd
that fills the psvar
array and then insert that value into the prompt with a form of %v
. For example:
precmd () psvar[1]=$(git_status_symbols);
PROMPT="╭─$user_host $current_dir $jobs $git_branch %1v
╰─%B$user_symbol%b "
Also, be aware that zsh has its own vcs support (for Git and others) which you may or may not want to leverage instead of writing custom code.
add a comment |
This is happening because your PROMPT
variable contains the command substitution $(git_status_symbols)
. This evaluation happens once during assignment and not on every expansion of PROMPT
.
The easiest way to fix this is by using a precmd
that fills the psvar
array and then insert that value into the prompt with a form of %v
. For example:
precmd () psvar[1]=$(git_status_symbols);
PROMPT="╭─$user_host $current_dir $jobs $git_branch %1v
╰─%B$user_symbol%b "
Also, be aware that zsh has its own vcs support (for Git and others) which you may or may not want to leverage instead of writing custom code.
add a comment |
This is happening because your PROMPT
variable contains the command substitution $(git_status_symbols)
. This evaluation happens once during assignment and not on every expansion of PROMPT
.
The easiest way to fix this is by using a precmd
that fills the psvar
array and then insert that value into the prompt with a form of %v
. For example:
precmd () psvar[1]=$(git_status_symbols);
PROMPT="╭─$user_host $current_dir $jobs $git_branch %1v
╰─%B$user_symbol%b "
Also, be aware that zsh has its own vcs support (for Git and others) which you may or may not want to leverage instead of writing custom code.
This is happening because your PROMPT
variable contains the command substitution $(git_status_symbols)
. This evaluation happens once during assignment and not on every expansion of PROMPT
.
The easiest way to fix this is by using a precmd
that fills the psvar
array and then insert that value into the prompt with a form of %v
. For example:
precmd () psvar[1]=$(git_status_symbols);
PROMPT="╭─$user_host $current_dir $jobs $git_branch %1v
╰─%B$user_symbol%b "
Also, be aware that zsh has its own vcs support (for Git and others) which you may or may not want to leverage instead of writing custom code.
answered Mar 8 at 23:31
brian m. carlsonbrian m. carlson
1,866211
1,866211
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55055662%2fzsh-theme-not-updating-from-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown