Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sjd-Risca opened this issue Apr 16, 2021 · 5 comments
Open

Comments

@Sjd-Risca
Copy link

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
Copy link
Owner

RichiH commented Apr 16, 2021

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
Copy link
Collaborator

alerque commented Apr 16, 2021

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
Copy link
Author

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
Copy link
Collaborator

alerque commented Apr 17, 2021

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 alerque reopened this Apr 17, 2021
@alerque
Copy link
Collaborator

alerque commented Apr 23, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants