तुम्हें पता है अगर यह कॉन्फ़िगर करने के लिए बैश संकेतzsh कर सकते हैं के रूप में सही पक्ष पर Git स्थिति/शाखा की जानकारी दिखाने के लिए संभव है? इंटरनेट से यह यादृच्छिक रूप से स्क्रीन शॉट दिखाता है कि मेरा क्या मतलब है।टर्मिनल के दाईं ओर गिट स्थिति जानकारी कैसे दिखाएं?
7
A
उत्तर
0
एक तरह से tput
उपयोग करने के लिए अपने टर्मिनल के कॉलम गिनती करने के लिए, और वर्ण कि मुद्रित करने के लिए छोड़ दिया और सही जा रहे हैं की संख्या subtrack, तो की संख्या के रूप में है कि नंबर का उपयोग किया जाएगा बाएं और दाएं पाठ के बीच की जगहें। लाइन बनाने के लिए printf
का उपयोग करें।
त्वरित उदाहरण:
left="[${status}]\[email protected]\h:\w\$ "
right="$(git symbolic-ref HEAD) $(date +%T)"
spaces="$(($(tput cols) - ${#left} - ${#right}))"
export PS1="$(printf "%s%${spaces}s\n" "$left" "$right")"
9
निम्नलिखित का प्रयास करें:
PS1='$(printf "%*s\r%s" $((COLUMNS-1)) "[$(git branch 2>/dev/null | grep '^*' | sed s/..//)] $(date +%H:%M:%S)" "[email protected]:$PWD$ ")'
ध्यान दें कि आपको ऐसा व्यवहार बिल्कुल ही पार्टी के साथ zsh रूप से मेल खाना कभी नहीं मिलेगा। उपरोक्त मामले में मैं निम्नलिखित differencies देखें: शीघ्र की
- सही भाग में अवरोध है जब आप एक आदेश (zsh के मामले में
accept-line
घटना) चलाते हैं। - यदि आप कुछ टाइप करते हैं तो प्रॉम्प्ट का दायां हिस्सा साफ़ कर दिया जाएगा और फिर
<C-u>
या<BS>
दबाएं। - अगर आप उस पर कुछ टाइप करते हैं और फिर टेक्स्ट हटाते हैं तो प्रॉम्प्ट का सही हिस्सा पुन: स्थापित नहीं किया जाएगा।
- यदि आप इस पर कुछ टाइप करते हैं तो प्रॉम्प्ट का सही हिस्सा गायब नहीं होगा, हालांकि इस भाग में टेक्स्ट ओवरराइट किया जाएगा।
1
आज मैंने इस तरह से कुछ बनाया है। पूरी तरह से परीक्षण अभी तक नहीं किया गया है ...
preprompt() {
rc=$?
c=31
[ $rc -eq 0 ] && c=32
PS1="\[$(color $c)\]$rc\[$(color 0)\] \t \w \$ "
# right "prompt"
# We cannot use $COLUMNS here, since in new shells the first prompt
# will get garbled then. Seems like the correct value of COLUMNS is
# in the shell init.
printf "%`tput cols`s`tput cr`" "${USER}@${HOST}"
}
PROMPT_COMMAND=preprompt
1
कोड के नीचे एक संदेश मिलता है जो लग रहा है पैदा करेगा की तरह:
यह की वजह से bash
में यह करने के लिए गैर trival है:
- Readline mode string takes up characters before the prompt is printed, जिसका अर्थ है कि
printf
समाधान कुछ मामलों में काम नहीं करेंगे।इस वजह से: - सभी (जैसे रंग) निकाल रहा है सही ढंग से प्रिंट करने योग्य दाएँ हाथ की ओर शीघ्र
__git_ps1
उपयोग करने के लिएgit
बढ़त मामलों__git_ps1
केवल कुछ में रंग outputting से निपटने के लिए की जरूरत की अवधि की गणना करने परिस्थितियों, और केवल$PS1
__git_ps1
उत्पादन में रंग की अनुमति दे, जबकिमें पूरे आरएचएस शीघ्र रैपिंग\[
और\]
(जो नेस्ट नहीं किया जा सकता)- इसके उत्पादन से पात्रों को हटाने के अंदरऔर
\]
सुनिश्चित करना है कि शीघ्र अजीब बातें करते नहीं है जब ब्राउज़िंग/संपादन/आदेशों
#!/bin/bash
# _options=$(shopt -op); set -exu # Save and set shell options for testing
##################
# Set the prompt # Sourced from .bashrc
##################
# Select git info displayed, see /usr/lib/git-core/git-sh-prompt for more
export GIT_PS1_SHOWCOLORHINTS=1 # Make pretty colours inside $PS1
export GIT_PS1_SHOWDIRTYSTATE=1 # '*'=unstaged, '+'=staged
export GIT_PS1_SHOWSTASHSTATE=1 # '$'=stashed
export GIT_PS1_SHOWUNTRACKEDFILES=1 # '%'=untracked
export GIT_PS1_SHOWUPSTREAM="verbose" # 'u='=no difference, 'u+1'=ahead by 1 commit
export GIT_PS1_STATESEPARATOR='' # No space between branch and index status
export GIT_PS1_DESCRIBE_STYLE="describe" # Detached HEAD style:
# describe relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
# contains relative to newer annotated tag (v1.6.3.2~35)
# branch relative to newer tag or branch (master~4)
# default exactly eatching tag
# Sets prompt like:
# [email protected]:~/prj/sample_app[exit]$ master*% u= | 30 Apr 22:27
_set_bash_prompt() {
# Set left hand side of the prompt
PS1="\[email protected]\h:\w\$ "
#
# Git status
#
# Save current state of user shopt settings promptvars and extglob
local user_shopt
user_shopt=$(shopt -p promptvars extglob)
# __git_ps1 usually returns literal text "${__git_ps1_branch_name}" rather
# than the contained branch name, eg "master". This prevents calculating
# the length of the printable characers in the RHS string (used to move the
# cursor that many columns left from the terminal's right edge.) However if
# "shopt promptvars" is unset, __git_ps1 it will include the dereferenced
# branch name instead.
shopt -qu promptvars
# extglob is required for the ${variable//@(pattern)/} replacements
shopt -qs extglob
# Allow disabling git status and no error if __git_ps1 undefined
if [[ ! -v _disable_git_prompt && $(type -t __git_ps1 2>/dev/null) == function ]]; then
# __git_ps1 will only make pretty colours inside $PS1
local old_PS1=$PS1
__git_ps1 "" "" "%s" # force colour; no default round bracket (decorations)
# Strip "\[" and "\[": non-printable character markers. __git_ps1 outputs
# them however the whole of the RHS prompt needs to be included in these
# markers, and they can't be nested.
git=${PS1//@(\\@(\[|\]))/}
PS1=$old_PS1
fi
#
# Right hand side of prompt
#
local rhs="" # String to be printed on the right hand side of terminal
# Create a string like: "25 Apr 13:15"
local date_time
printf -v date_time "%(%e %b %H:%M)T" -1 # -1 is current time
# Format the RHS prompt
[[ -n $git ]] && rhs="$git | " #"
rhs+="\e[0;1;31m${date_time}"
# Strip ANSI CSI commands (eg colours) to enble counting the length of
# printable characters, giving offset of cursor from terminal RHS edge (from
# https://www.commandlinefu.com/commands/view/12043/remove-color-special-escape-ansi-codes-from-text-with-sed)
# Neither bash not sed support lookbehind zero-length assertions, so it's not
# possible to ignore "\\e", (ie a literal '\' followed by a literal 'e'), yet
# still remove "\e" (ie ESC)
local rhs_printable=${rhs//@(\\@(\[|]|[Ee]\[*([0-9;])[a-zA-Z]))/}
# or, in using sed (but requires exec):
# local rhs_printable=$(sed -e 's,\\[][]\|\\[Ee]\[\([0-9;]\)*[A-Za-z],,g' <<< "$rhs")
# Reference: https://en.wikipedia.org/wiki/ANSI_escape_code
local Save='\e[s' # Save cursor position
local Rest='\e[u' # Restore cursor to save point
# Save cursor position, jump to (right hand edge minus N columns) where N is
# the length of the printable RHS string. Print the RHS string, then return
# to the saved position and print the LHS prompt.
# Note: "\[" and "\]" are used so that bash can calculate the number of
# printed characters so that the prompt doesn't do strange things when
# command line editing/browsing/completion. Ensure that these are not nested.
PS1="\[\e[0m${Save}\e[$((COLUMNS - ${#rhs_printable}))G${rhs}${Rest}\]${PS1}"
eval "$user_shopt"
}
# eval "$_options"; unset _options # Restore previous shell options from line 2
संबंधित मुद्दे
- 1. दाईं ओर
- 2. दाईं ओर एक div कंटेनर
- 3. दाईं ओर मेनू?
- 4. दाएं बार्टबटन इटिम जानकारी बटन, दाईं ओर कोई जगह नहीं
- 5. दाईं ओर छुपाएं नेविगेशन नियंत्रक
- 6. टेक्स्ट के दाईं ओर एंड्रॉइड रेडियोबटन विकल्प
- 7. जावास्क्रिप्ट: किसी फ़ंक्शन के दाईं ओर बाध्यकारी?
- 8. एक TPopupMenu को फ़ॉर्म के दाईं ओर दाईं ओर संरेखित करें?
- 9. शीर्षलेख के दाईं ओर बटन जोड़ें
- 10. पूर्ण स्थिति के साथ दाईं ओर एक div को कैसे रखें
- 11. चेकबॉक्स के दाईं ओर अवांछित रिक्त स्थान को कैसे हटाएं?
- 12. टूलबार के दाईं ओर एक बटन कैसे जोड़ें?
- 13. MySQL वर्तमान कनेक्शन जानकारी दिखाएं
- 14. दाईं ओर एक इनलाइन-ब्लॉक तत्व को कैसे संरेखित करें?
- 15. जावा स्विंग; मैं इसे कैसे बना सकता हूं ताकि प्रोग्राम स्क्रीन के दाईं ओर दाईं ओर शुरू हो सके?
- 16. टर्मिनल में गिट स्थिति सूची से कैसे बाहर निकलें?
- 17. पाठ-संरेखण उचित है लेकिन दाईं ओर?
- 18. एक निश्चित स्थिति के साथ दाईं तरफ तैरने वाली नौसेना?
- 19. Jquery ui accordion - दाईं ओर एक आइकन कैसे जोड़ें?
- 20. गिट स्थिति की जानकारी के साथ "एलएस" बढ़ाया?
- 21. टेक्स्टमैट फ़ाइल एक्सप्लोरर को दाईं ओर कैसे स्थानांतरित करें?
- 22. टर्मिनल कर्सर स्थिति
- 23. स्विंग - मास्कफॉर्मेटर - टेक्स्टफील्ड के दाईं ओर से नंबर दर्ज करें
- 24. कॉल के बीच में जानकारी दिखाएं
- 25. एंड्रॉइड: दाईं ओर स्पिनर टेक्स्ट संरेखण लेकिन केंद्रित नहीं
- 26. मैं Emacs 23 में दाईं ओर के बजाय नीचे संकलन बफर कैसे प्राप्त कर सकता हूं?
- 27. mysql: substring जो दाईं ओर पहली घटना देता है? (subrstring ?!)
- 28. Google+ बटन दाईं ओर खाली स्थान/मार्जिन हटाएं दाएं
- 29. टर्मिनल में गिट प्रतिबद्धता वीआईएम खोलता है, लेकिन टर्मिनल
- 30. अनुक्रम आरेख पर "अगर" स्थिति कैसे दिखाएं?
mmm को पूरा करने, मैं सिर्फ देखा था इस _same line_ पर है। मुझे नहीं लगता कि^काम करेगा। लगता है जैसे आपको '[एन] शापों की सामग्री पर अपने हाथों को और अधिक प्राप्त करने की आवश्यकता है। – c00kiemon5ter