Compare commits
5 Commits
better-syn
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e2a85d1fa1 | |||
| d32ca6ef4b | |||
| f8ee8e3088 | |||
| 319b3fdd8b | |||
| 821ebfeaa1 |
1
.bash-aliases
Normal file
1
.bash-aliases
Normal file
@ -0,0 +1 @@
|
||||
alias please=`sudo -p 'What's the magic word? '`
|
||||
@ -1,93 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
## Uncomment to disable git info
|
||||
#POWERLINE_GIT=0
|
||||
|
||||
__powerline() {
|
||||
# Colors
|
||||
COLOR_RESET='\[\033[m\]'
|
||||
COLOR_CWD=${COLOR_CWD:-'\[\033[0;34m\]'} # blue
|
||||
COLOR_GIT=${COLOR_GIT:-'\[\033[0;36m\]'} # cyan
|
||||
COLOR_SUCCESS=${COLOR_SUCCESS:-'\[\033[0;32m\]'} # green
|
||||
COLOR_FAILURE=${COLOR_FAILURE:-'\[\033[0;31m\]'} # red
|
||||
|
||||
# Symbols
|
||||
SYMBOL_GIT_BRANCH=${SYMBOL_GIT_BRANCH:-⑂}
|
||||
SYMBOL_GIT_MODIFIED=${SYMBOL_GIT_MODIFIED:-*}
|
||||
SYMBOL_GIT_PUSH=${SYMBOL_GIT_PUSH:-↑}
|
||||
SYMBOL_GIT_PULL=${SYMBOL_GIT_PULL:-↓}
|
||||
|
||||
if [[ -z "$PS_SYMBOL" ]]; then
|
||||
case "$(uname)" in
|
||||
Darwin) PS_SYMBOL='';;
|
||||
Linux) PS_SYMBOL='$';;
|
||||
*) PS_SYMBOL='%';;
|
||||
esac
|
||||
fi
|
||||
|
||||
__git_info() {
|
||||
[[ $POWERLINE_GIT = 0 ]] && return # disabled
|
||||
hash git 2>/dev/null || return # git not found
|
||||
local git_eng="env LANG=C git" # force git output in English to make our work easier
|
||||
|
||||
# get current branch name
|
||||
local ref=$($git_eng symbolic-ref --short HEAD 2>/dev/null)
|
||||
|
||||
if [[ -n "$ref" ]]; then
|
||||
# prepend branch symbol
|
||||
ref=$SYMBOL_GIT_BRANCH$ref
|
||||
else
|
||||
# get tag name or short unique hash
|
||||
ref=$($git_eng describe --tags --always 2>/dev/null)
|
||||
fi
|
||||
|
||||
[[ -n "$ref" ]] || return # not a git repo
|
||||
|
||||
local marks
|
||||
|
||||
# scan first two lines of output from `git status`
|
||||
while IFS= read -r line; do
|
||||
if [[ $line =~ ^## ]]; then # header line
|
||||
[[ $line =~ ahead\ ([0-9]+) ]] && marks+=" $SYMBOL_GIT_PUSH${BASH_REMATCH[1]}"
|
||||
[[ $line =~ behind\ ([0-9]+) ]] && marks+=" $SYMBOL_GIT_PULL${BASH_REMATCH[1]}"
|
||||
else # branch is modified if output contains more lines after the header line
|
||||
marks="$SYMBOL_GIT_MODIFIED$marks"
|
||||
break
|
||||
fi
|
||||
done < <($git_eng status --porcelain --branch 2>/dev/null) # note the space between the two <
|
||||
|
||||
# print the git branch segment without a trailing newline
|
||||
printf " $ref$marks"
|
||||
}
|
||||
|
||||
ps1() {
|
||||
# Check the exit code of the previous command and display different
|
||||
# colors in the prompt accordingly.
|
||||
if [ $? -eq 0 ]; then
|
||||
local symbol="$COLOR_SUCCESS $PS_SYMBOL $COLOR_RESET"
|
||||
else
|
||||
local symbol="$COLOR_FAILURE $PS_SYMBOL $COLOR_RESET"
|
||||
fi
|
||||
|
||||
local cwd="$COLOR_CWD\w$COLOR_RESET"
|
||||
# Bash by default expands the content of PS1 unless promptvars is disabled.
|
||||
# We must use another layer of reference to prevent expanding any user
|
||||
# provided strings, which would cause security issues.
|
||||
# POC: https://github.com/njhartwell/pw3nage
|
||||
# Related fix in git-bash: https://github.com/git/git/blob/9d77b0405ce6b471cb5ce3a904368fc25e55643d/contrib/completion/git-prompt.sh#L324
|
||||
if shopt -q promptvars; then
|
||||
__powerline_git_info="$(__git_info)"
|
||||
local git="$COLOR_GIT\${__powerline_git_info}$COLOR_RESET"
|
||||
else
|
||||
# promptvars is disabled. Avoid creating unnecessary env var.
|
||||
local git="$COLOR_GIT$(__git_info)$COLOR_RESET"
|
||||
fi
|
||||
|
||||
PS1="$cwd$git$symbol"
|
||||
}
|
||||
|
||||
PROMPT_COMMAND="ps1${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
|
||||
}
|
||||
|
||||
__powerline
|
||||
unset __powerline
|
||||
13
.bashrc
13
.bashrc
@ -116,5 +116,16 @@ fi
|
||||
bind -r '\C-s'
|
||||
stty -ixon
|
||||
|
||||
EDITOR=/usr/bin/vim
|
||||
SUDO_EDITOR=/usr/bin/vim
|
||||
VISUAL=/usr/bin/vim
|
||||
|
||||
source ~/.bash-aliases
|
||||
source ~/.bash-powerline
|
||||
|
||||
function _update_ps1() {
|
||||
PS1=$(powerline-shell $?)
|
||||
}
|
||||
|
||||
if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
|
||||
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
|
||||
fi
|
||||
|
||||
13
.config/powerline-shell/config.json
Normal file
13
.config/powerline-shell/config.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"segments": [
|
||||
"virtual_env",
|
||||
"username",
|
||||
"hostname",
|
||||
"ssh",
|
||||
"cwd",
|
||||
"git",
|
||||
"hg",
|
||||
"jobs",
|
||||
"root"
|
||||
]
|
||||
}
|
||||
2
.vimrc
2
.vimrc
@ -1,4 +1,4 @@
|
||||
color desert
|
||||
color slate
|
||||
syntax on
|
||||
|
||||
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
|
||||
|
||||
@ -2,4 +2,6 @@
|
||||
.vimrc
|
||||
.gitconfig
|
||||
.bashrc
|
||||
.bash-powerline
|
||||
.bash-aliases
|
||||
.config/powerline-shell/
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user