2011-02-23 15 views
8

खाती है मैंने पेपकोड के स्क्रीनकास्ट में से एक .bashrc का उपयोग किया है।.bashrc ब्रेक, खोल में दर्ज दूसरी पंक्ति पहली पंक्ति

# If not running interactively, don't do anything 
[ -z "$PS1" ] && return 

# check the window size after each command and, if necessary, 
# update the values of LINES and COLUMNS. 
shopt -s checkwinsize 

# set variable identifying the chroot you work in (used in the prompt below) 
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then 
    debian_chroot=$(cat /etc/debian_chroot) 
fi 

# set a fancy prompt (non-color, overwrite the one in /etc/profile) 
PS1='${debian_chroot:+($debian_chroot)}\[email protected]\h:\w\$ ' 

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default. 
# If this is an xterm set the title to [email protected]:dir 
#case "$TERM" in 
#xterm*|rxvt*) 
# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' 
# ;; 
#*) 
# ;; 
#esac 

# enable bash completion in interactive shells 
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then 
# . /etc/bash_completion 
#fi 

# sudo hint 
if [ ! -e "$HOME/.sudo_as_admin_successful" ]; then 
    case " $(groups) " in *\ admin\ *) 
    if [ -x /usr/bin/sudo ]; then 
    cat <<-EOF 
    To run a command as administrator (user "root"), use "sudo <command>". 
    See "man sudo_root" for details. 

    EOF 
    fi 
    esac 
fi 

# if the command-not-found package is installed, use it 
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found ]; then 
    function command_not_found_handle { 
      # check because c-n-f could've been removed in the meantime 
       if [ -x /usr/lib/command-not-found ]; then 
      /usr/bin/python /usr/lib/command-not-found -- $1 
        return $? 
       elif [ -x /usr/share/command-not-found ]; then 
      /usr/bin/python /usr/share/command-not-found -- $1 
        return $? 
     else 
      return 127 
     fi 
    } 
fi 

. ~/bin/bash_colors.sh 

#load bash aliases 
if [ -f ~/.bash_aliases ]; then 
. ~/.bash_aliases 
fi 

# Unbreak broken, non-colored terminal 
export TERM='xterm-color' 
alias ls='ls -G' 
alias ll='ls -lG' 
export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd" 
export GREP_OPTIONS="--color" 

# Erase duplicates in history 
export HISTCONTROL=erasedups 
# Store 10k history entries 
export HISTSIZE=10000 
# Append to the history file when exiting instead of overwriting it 
shopt -s histappend 

function minutes_since_last_commit { 
    now=`date +%s` 
    last_commit=`git log --pretty=format:'%at' -1` 
    seconds_since_last_commit=$((now-last_commit)) 
    minutes_since_last_commit=$((seconds_since_last_commit/60)) 
    echo $minutes_since_last_commit 
} 
grb_git_prompt() { 
    local g="$(__gitdir)" 
    if [ -n "$g" ]; then 
     local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit` 
     if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then 
      local COLOR=${RED} 
     elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then 
      local COLOR=${YELLOW} 
     else 
      local COLOR=${GREEN} 
     fi 
     local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m${NORMAL}" 
     # The __git_ps1 function inserts the current git branch where %s is 
     local GIT_PROMPT=`__git_ps1 "(%s|${SINCE_LAST_COMMIT})"` 
     echo ${GIT_PROMPT} 
    fi 
} 

export PS1='$(grb_git_prompt)$ ' 

gd() { git diff $* | view -; } 
gdc() { gd --cached $*; } 

source ~/bin/git-completion.bash 

मैं पुष्टि कर सकता हूं कि त्रुटि grb_git_promit में है। क्या होता है कि खोल में टाइप की गई दूसरी पंक्तियां पहली पंक्ति को ओवरराइट कर रही हैं। क्या कोई इस से मेरी मदद कर सकता है?

संपादित करें:

grb_git_prompt() { 
    local g="$(__gitdir)" 
    if [ -n "$g" ]; then 
     local MINUTES_SINCE_LAST_COMMIT=`minutes_since_last_commit` 
     if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then 
      local COLOR="\[\033[0;31m\]" 
     elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then 
      local COLOR="\[\033[0;37m\]" 
     else 
      local COLOR="\[\033[0;32m\]" 
     fi 
     local SINCE_LAST_COMMIT="${COLOR}$(minutes_since_last_commit)m$" 
     # The __git_ps1 function inserts the current git branch where %s is 
    echo "$(__git_ps1 '(%s|')${SINCE_LAST_COMMIT}" 
    fi 
} 
+1

मैं समस्या को पूरी तरह से समझ नहीं पा रहा हूं, लेकिन मैंने इसका परीक्षण किया और यह मेरे लिए ठीक काम कर रहा है। –

+0

जब मैं एक लंबी कमांड टाइप करता हूं तो "gedit/really/long/filename/that/take/up/two/lines/in/bash/shell" होता है, यह "बैश खोल सहयोगी/लंबा/फ़ाइल नाम/वह/ले/अप/दो/लाइनों/में। " मुझे यकीन नहीं है कि क्या मैं इसे ठीक से समझा रहा हूं, मूल रूप से जब आदेश दो पंक्तियों में जाता है, तो दूसरी पंक्ति में जाने के बजाय, यह पहली पंक्ति खाने लगता है। यदि आप "लाइन की शुरुआत से बैश लाइन रैपिंग ओवरराइट्स" पर Google हैं, तो आपको पता चलेगा कि मैं किस बारे में बात कर रहा हूं। (मैंने किया, लेकिन कोई जवाब नहीं मिला।) –

+0

@ सेंथिल: 'लाल', 'येलो', 'ग्रीन' और 'सामान्य' कहां से आते हैं? मुझे यकीन है कि आपकी समस्या वहां है, क्योंकि वे संभावित रूप से टर्मिनल एस्केप अनुक्रम हैं। यदि वे किसी भी तरह से स्वचालित रूप से जेनरेट किए जा रहे हैं, तो यह सुनिश्चित करने के लिए जांचें कि 'TERM' का उचित मूल्य है। साथ ही, मुझे संदेह है कि आप असाइन करते समय उन्हें उद्धृत करना चाहेंगे: 'COLOR =" $ {RED} "'। आप निश्चित रूप से पुष्टि कर सकते हैं कि प्रॉम्प्ट से रंग को हटाकर यह समस्या है या नहीं। – Cascabel

उत्तर

26

आप अपने शीघ्र में रंग और अन्य गैर मुद्रण भागने दृश्यों है, तो आप उन्हें बच गए एकल ब्रैकेट के साथ चारों ओर है।

PS1='\[\033[38;5;1m\]some red text\[\033[0m\]\$ ' 

कौन सा शीघ्र डिफ़ॉल्ट रंग में "कुछ लाल पाठ" में लाल और डॉलर चिह्न (या "#") प्रदर्शित करने के लिए कारण होगा: यहाँ एक सरल उदाहरण है।

यहाँ एक और तरीका एक ही बात करने के लिए है:

red='\033[38;5;1m' 
none='\033[0m' 
PS1='\[$red\]some red text\[$none\]\$ ' 

वैसे, इस अधिक portably करते हैं और चर के कम जटिल निर्माण हुआ है करने के लिए:

red=$(tput setaf 1) 
none=$(tput sgr0) 

के लिए man 5 terminfo देखें सेटिंग्स पर अधिक जानकारी।

+0

मैंने रंगों को बदल दिया डी ने एकल भागने वाले ब्रैकेट जोड़े (नए फ़ंक्शन के लिए संपादन देखें), लेकिन मुझे लगता है कि (होम | \ [\ 033 [0; 31 मीटर \] 541m $ –

+0

@ सेंथिल: आपको असाइनमेंट में भागने वाले ब्रैकेट को ' अन्य चर के बजाय PS1'। यदि आपको गतिशील प्रॉम्प्ट में रंग सेट करने की आवश्यकता है तो इसे जारी किए जाने पर 'PS1' सेट करने के लिए '$ PROMPT_COMMAND'' का उपयोग करें। –

+0

मैंने .zsh में बदलने का फैसला किया और यह वहां पर बेकार ढंग से काम करता है। आपकी सहायता के लिए धन्यवाद. –

संबंधित मुद्दे