Skip to content

Commit

Permalink
Add hint on the PROMPT_DIRTRIM variable
Browse files Browse the repository at this point in the history
Resolves #22
  • Loading branch information
Scriptim committed Jan 26, 2024
1 parent 65aee5d commit 0019e50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ h3
opacity: 0.6
line-height: 1.5
&+.hint
margin-top: 1em
.dark
h2,
h3
Expand Down
27 changes: 20 additions & 7 deletions src/components/output/PS1Variable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="ps1" :class="{ dark: darkMode }">
<span>{{ ps1 }}</span>
</div>
<div class="hint" v-if="hasAdvancedGitPromptElement">
<div class="hint" v-if="hasElement('Advanced Git Prompt')">
The <code>Advanced Git Prompt</code> element requires some extra work: Copy the
<a
href="https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh"
Expand All @@ -23,6 +23,17 @@
By default the status will only contain the current branch name, however you can include more information using
global or repository-local configuration options (which are also described in <code>git-prompt.sh</code>).
</div>
<div class="hint" v-if="hasElement('Working Directory') || hasElement('Working Directory (Basename)')">
You can limit the number of components in the working directory path by setting the
<a
href="https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PROMPT_005fDIRTRIM"
target="_blank"
rel="noopener noreferrer"
>
<code>PROMPT_DIRTRIM</code>
</a>
environment variable in your <code>~/.bashrc</code> file.
</div>
</template>

<script lang="ts">
Expand Down Expand Up @@ -251,12 +262,6 @@ export default defineComponent({
darkMode(): boolean {
return darkMode().enabled;
},
/**
* Returns `true` if there exists at least one 'Advanced Git Prompt' element.
*/
hasAdvancedGitPromptElement(): boolean {
return prompt.state().elements.some((element) => element.data.type.name === 'Advanced Git Prompt');
},
},
components: { IconButton },
methods: {
Expand All @@ -266,6 +271,14 @@ export default defineComponent({
copyToClipboard() {
navigator.clipboard.writeText(this.ps1);
},
/**
* Returns `true` if there exists at least one prompt element with the given name.
*
* @param name the case-insensitive name of the prompt element
*/
hasElement(name: string): boolean {
return prompt.state().elements.some((element) => element.data.type.name.toLowerCase() === name.toLowerCase());
},
},
});
</script>
Expand Down

0 comments on commit 0019e50

Please sign in to comment.