RichiH / vcsh

config manager based on Git
GNU General Public License v2.0
2.2k stars 124 forks source link

Confused whether inside command "vcsh enter <repo_name>" or already quit #297

Open Sjd-Risca opened 3 years ago

Sjd-Risca commented 3 years ago

Hi, often I use the command enter is order to do some action on a specific repository.

The issue that I'm facing is that - maybe due low brain's memory resources - I forget if I'm still inside the vcsh subshell or if I already quit it. Therefore at current time I've aliased the command to the following:

#!/bin/bash                                                                                                                                            

[ "$1" == "enter" ] && repo=$2 || repo=$1
PS1="($repo) $ " $SHELL /usr/bin/vcsh $@

Do you thing could make sense integrate such functionality into vcsh itself? It would be enough to patch appropriately where the variable $SHELL is used. For bash could work something like like: bash --rcfile <(echo "PS1=\"(change) ${PS1}\"")

RichiH commented 3 years ago

Changing PS1 just so is somewhat risky, but vcsh sets $VCSH_REPO_NAME for precisely this reason; I use it in my own shell, as well. Maybe we should make that clearer in the docs?

alerque commented 3 years ago

Like Richard said, a command line tool manipulating the parent shell is kind of a minefield situation and it would not be appropriate for VCSH to do this and at the same time expect the user's regular shell to work. The only way we could handle this more directly is with a REPL interface that doesn't claim to be a full shell following the user's other preferences.

Also like he said $VCSH_REPO_NAME and other environment variables are set just for this use. You can configure your existing shell prompt to alert you if you are in a VCSH repo. For example my own shell (Zsh with prezto using the Powerline10k theme) sets it up like this:

typeset -g POWERLEVEL9K_CUSTOM_VCSH=zsh_vcsh
typeset -g POWERLEVEL9K_CUSTOM_VCSH_BACKGROUND='202'
typeset -g POWERLEVEL9K_CUSTOM_VCSH_FOREGROUND='234'
zsh_vcsh () {
    echo -n ${VCSH_REPO_NAME}
}
typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(root_indicator user host dir custom_vcsh vcs)

The resulting shell prompt before and after entering a VCSH repo looks like this:

image

Another thing to mention if it interests you is that the next version of starship (v0.52.0) will include out of the box support for showing VCSH information. You can use the Git HEAD version now or check it out after the next release. Support was contributed here.

Some sample configs for various shells in the docs would probably be a good plan.

Sjd-Risca commented 3 years ago

Thank you @RichiH and @alerque for your fast reply, I'd totally agree with your observation: the usage of variable VCSH_REPO_NAME would be more than enough and safer.

From my point of view it could be helpful to highlight such usage into the docs.

The idea of updating the PS1 was stolen from virtualenv, but I agree that - safety apart - sometimes it is also really annoying especially when it messes with the console layout.

alerque commented 3 years ago

I understand this issue might be resolved for you, but lets keep the issue open to track getting this end of things better documented for other first time users. If it's noisy for you you can unsubscribe from notifications to this issue from the sidebar.

alerque commented 3 years ago

Out of the box support for VCSH info in the prompt shipped in Starship v0.52.1.