Erreur32 bu gisti düzenledi 6 months ago. Düzenlemeye git
Değişiklik yok
Jesse Cooke bu gisti düzenledi 12 years ago. Düzenlemeye git
2 files changed, 162 insertions
prompt.sh
| @@ -37,4 +37,5 @@ fi | |||
| 37 | 37 | unset color_prompt force_color_prompt | |
| 38 | 38 | ||
| 39 | 39 | export PS1=$(parse_ps1) | |
| 40 | + | source "$HOME/bin/ps1_functions" | |
| 40 | 41 | ps1_set --prompt ∴ | |
ps1_functions.sh(dosya oluşturuldu)
| @@ -0,0 +1,161 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | ||
| 3 | + | # | |
| 4 | + | # Source this file in your ~/.bash_profile or interactive startup file. | |
| 5 | + | # This is done like so: | |
| 6 | + | # | |
| 7 | + | # [[ -s "$HOME/.rvm/contrib/ps1_functions" ]] && | |
| 8 | + | # source "$HOME/.rvm/contrib/ps1_functions" | |
| 9 | + | # | |
| 10 | + | # Then in order to set your prompt you simply do the following for example | |
| 11 | + | # | |
| 12 | + | # Examples: | |
| 13 | + | # | |
| 14 | + | # ps1_set --prompt ∫ | |
| 15 | + | # | |
| 16 | + | # or | |
| 17 | + | # | |
| 18 | + | # ps1_set --prompt ∴ | |
| 19 | + | # | |
| 20 | + | # This will yield a prompt like the following, for example, | |
| 21 | + | # | |
| 22 | + | # 00:00:50 wayneeseguin@GeniusAir:~/projects/db0/rvm/rvm (git:master:156d0b4) ruby-1.8.7-p334@rvm | |
| 23 | + | # ∴ | |
| 24 | + | # | |
| 25 | + | ps1_titlebar() | |
| 26 | + | { | |
| 27 | + | case $TERM in | |
| 28 | + | (xterm*|rxvt*) | |
| 29 | + | printf "%s" "\033]0;\\u@\\h: \W\\007" | |
| 30 | + | ;; | |
| 31 | + | esac | |
| 32 | + | } | |
| 33 | + | ||
| 34 | + | ps1_identity() | |
| 35 | + | { | |
| 36 | + | if (( $UID == 0 )) ; then | |
| 37 | + | printf "%s" "\[\033[31m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[35m\]:\w\[\033[0m\] " | |
| 38 | + | else | |
| 39 | + | printf "%s" "\[\033[32m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[35m\]:\w\[\033[0m\] " | |
| 40 | + | fi | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | ps1_git() | |
| 44 | + | { | |
| 45 | + | local branch="" sha1="" line="" attr="" color=0 | |
| 46 | + | ||
| 47 | + | shopt -s extglob # Important, for our nice matchers :) | |
| 48 | + | ||
| 49 | + | command -v git >/dev/null 2>&1 || { | |
| 50 | + | printf " \033[1;37m\033[41m[git not found]\033[m " | |
| 51 | + | return 0 | |
| 52 | + | } | |
| 53 | + | ||
| 54 | + | branch=$(git symbolic-ref -q HEAD 2>/dev/null) || return 0 # Not in git repo. | |
| 55 | + | branch=${branch##refs/heads/} | |
| 56 | + | ||
| 57 | + | # Now we display the branch. | |
| 58 | + | sha1=$(git rev-parse --short --quiet HEAD) | |
| 59 | + | ||
| 60 | + | case "${branch:-"(no branch)"}" in | |
| 61 | + | production|prod) attr="1;37m\033[" ; color=41 ;; # red | |
| 62 | + | master|deploy) color=31 ;; # red | |
| 63 | + | stage|staging) color=33 ;; # yellow | |
| 64 | + | dev|develop|development) color=34 ;; # blue | |
| 65 | + | next) color=36 ;; # gray | |
| 66 | + | *) | |
| 67 | + | if [[ -n "${branch}" ]] ; then # Feature Branch :) | |
| 68 | + | color=32 # green | |
| 69 | + | else | |
| 70 | + | color=0 # reset | |
| 71 | + | fi | |
| 72 | + | ;; | |
| 73 | + | esac | |
| 74 | + | ||
| 75 | + | [[ $color -gt 0 ]] && | |
| 76 | + | printf "\[\033[${attr}${color}m\](git:${branch}$(ps1_git_status):$sha1)\[\033[0m\] " | |
| 77 | + | } | |
| 78 | + | ||
| 79 | + | ps1_git_status() | |
| 80 | + | { | |
| 81 | + | local git_status="$(git status 2>/dev/null)" | |
| 82 | + | ||
| 83 | + | [[ "${git_status}" = *deleted* ]] && printf "%s" "-" | |
| 84 | + | [[ "${git_status}" = *Untracked[[:space:]]files:* ]] && printf "%s" "+" | |
| 85 | + | [[ "${git_status}" = *modified:* ]] && printf "%s" "*" | |
| 86 | + | } | |
| 87 | + | ||
| 88 | + | ps1_ruby() | |
| 89 | + | { | |
| 90 | + | printf "%s %s" $(echo $RUBY_ENGINE) $(echo $RUBY_VERSION) | |
| 91 | + | } | |
| 92 | + | ||
| 93 | + | ps1_update() | |
| 94 | + | { | |
| 95 | + | local prompt_char='$' separator="\n" notime=0 | |
| 96 | + | ||
| 97 | + | (( $UID == 0 )) && prompt_char='#' | |
| 98 | + | ||
| 99 | + | while [[ $# -gt 0 ]] ; do | |
| 100 | + | local token="$1" ; shift | |
| 101 | + | ||
| 102 | + | case "$token" in | |
| 103 | + | --trace) | |
| 104 | + | export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > " | |
| 105 | + | set -o xtrace | |
| 106 | + | ;; | |
| 107 | + | --prompt) | |
| 108 | + | prompt_char="$1" | |
| 109 | + | shift | |
| 110 | + | ;; | |
| 111 | + | --noseparator) | |
| 112 | + | separator="" | |
| 113 | + | ;; | |
| 114 | + | --separator) | |
| 115 | + | separator="$1" | |
| 116 | + | shift | |
| 117 | + | ;; | |
| 118 | + | --notime) | |
| 119 | + | notime=1 | |
| 120 | + | ;; | |
| 121 | + | *) | |
| 122 | + | true # Ignore everything else. | |
| 123 | + | ;; | |
| 124 | + | esac | |
| 125 | + | done | |
| 126 | + | ||
| 127 | + | if (( notime > 0 )) ; then | |
| 128 | + | PS1="$(ps1_titlebar)$(ps1_identity)$(ps1_git)$(ps1_ruby)${separator}${prompt_char} " | |
| 129 | + | else | |
| 130 | + | PS1="$(ps1_titlebar)\D{%H:%M:%S} $(ps1_identity)$(ps1_git)$(ps1_ruby)${separator}${prompt_char} " | |
| 131 | + | fi | |
| 132 | + | } | |
| 133 | + | ||
| 134 | + | ps2_set() | |
| 135 | + | { | |
| 136 | + | PS2=" \[\033[0;40m\]\[\033[0;33m\]> \[\033[1;37m\]\[\033[1m\]" | |
| 137 | + | } | |
| 138 | + | ||
| 139 | + | ps4_set() | |
| 140 | + | { | |
| 141 | + | export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > " | |
| 142 | + | } | |
| 143 | + | ||
| 144 | + | # WARNING: This clobbers your PROMPT_COMMAND so if you need to write your own, call | |
| 145 | + | # ps1_update within your PROMPT_COMMAND with the same arguments you pass | |
| 146 | + | # to ps1_set | |
| 147 | + | # | |
| 148 | + | # The PROMPT_COMMAND is used to help the prompt work if the separator is not a new line. | |
| 149 | + | # In the event that the separtor is not a new line, the prompt line may become distored if | |
| 150 | + | # you add or delete a certian number of characters, making the string wider than the | |
| 151 | + | # $COLUMNS + len(your_input_line). | |
| 152 | + | # This orginally was done with callbacks within the PS1 to add in things like the git | |
| 153 | + | # commit, but this results in the PS1 being of an unknown width which results in the prompt | |
| 154 | + | # being distored if you add or remove a certain number of characters. To work around this | |
| 155 | + | # it now uses the PROMPT_COMMAND callback to re-set the PS1 with a known width of chracters | |
| 156 | + | # each time a new command is entered. see PROMPT_COMMAND for more details. | |
| 157 | + | # | |
| 158 | + | ps1_set() | |
| 159 | + | { | |
| 160 | + | PROMPT_COMMAND="ps1_update $@" | |
| 161 | + | } | |
Jesse Cooke bu gisti düzenledi 12 years ago. Düzenlemeye git
1 file changed, 40 insertions
prompt.sh(dosya oluşturuldu)
| @@ -0,0 +1,40 @@ | |||
| 1 | + | txtwht="\[\e[00m\]" # White | |
| 2 | + | txtred="\[\e[0;31m\]" # Red | |
| 3 | + | txtgrn="\[\e[0;32m\]" # Green | |
| 4 | + | txtpur="\[\e[0;35m\]" # Purple | |
| 5 | + | txtblu="\[\e[0;34m\]" # Blue | |
| 6 | + | bldgrn="\[\e[1;32m\]" # Green | |
| 7 | + | bldcyn="\[\e[1;36m\]" # Cyan | |
| 8 | + | ||
| 9 | + | function parse_git_this_branch { | |
| 10 | + | git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
| 11 | + | } | |
| 12 | + | ||
| 13 | + | function parse_git_deleted { | |
| 14 | + | [[ $(git status 2> /dev/null | grep deleted:) != "" ]] && echo "-" | |
| 15 | + | } | |
| 16 | + | function parse_git_added { | |
| 17 | + | [[ $(git status 2> /dev/null | grep "Untracked files:") != "" ]] && echo "+" | |
| 18 | + | } | |
| 19 | + | function parse_git_modified { | |
| 20 | + | [[ $(git status 2> /dev/null | grep modified:) != "" ]] && echo "*" | |
| 21 | + | } | |
| 22 | + | function parse_git_dirty { | |
| 23 | + | echo "$(parse_git_added)$(parse_git_modified)$(parse_git_deleted)" | |
| 24 | + | } | |
| 25 | + | function parse_git_branch { | |
| 26 | + | git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/" | |
| 27 | + | } | |
| 28 | + | function parse_ps1 { | |
| 29 | + | echo "${bldcyn}[\W]${txtwht}\$(parse_git_branch)\n$> " | |
| 30 | + | } | |
| 31 | + | ||
| 32 | + | if [ "$color_prompt" = yes ]; then | |
| 33 | + | PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
| 34 | + | else | |
| 35 | + | PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
| 36 | + | fi | |
| 37 | + | unset color_prompt force_color_prompt | |
| 38 | + | ||
| 39 | + | export PS1=$(parse_ps1) | |
| 40 | + | ps1_set --prompt ∴ | |