2017-02-09 11:00:03 +01:00
|
|
|
|
|
|
|
# Get ourselves a nice prompt
|
2017-05-19 17:06:37 +02:00
|
|
|
ks() { s="$?" ; $* ; return "$s" ; }
|
2017-08-02 10:01:26 +02:00
|
|
|
prompt_git() {
|
|
|
|
if git status 2>/dev/null 1>&2; then
|
2018-10-22 23:09:42 +02:00
|
|
|
local branch="$(git branch | sed -n 's/^\* (*\(.* \)*\([^ )]*\))*$/\2/p')"
|
|
|
|
local behind="$(git status --branch --porcelain=2 | sed -n 's/^# branch\.ab.*-\([^0].*\)$/⇃\1/p')"
|
|
|
|
local before="$(git status --branch --porcelain=2 | sed -n 's/^# branch\.ab +\([^0].*\) .*$/↿\1/p')"
|
|
|
|
local status="$(git status --porcelain | sed 's/\(..\).*/\1/' | cat <(echo OK) - | tail -1)"
|
|
|
|
|
|
|
|
echo " (${branch}${behind}${before}|${status})"
|
2017-08-02 10:01:26 +02:00
|
|
|
fi
|
|
|
|
}
|
2017-05-19 17:06:37 +02:00
|
|
|
prompt_pwd() {
|
2017-10-20 11:28:10 +02:00
|
|
|
pwd | sed -e "s_${HOME}_~_" -e 's_\(/*\.*.\)[^/]*/_\1/_g'
|
2017-05-19 17:06:37 +02:00
|
|
|
}
|
2018-11-30 10:01:33 +01:00
|
|
|
prompt_agent() {
|
|
|
|
[ -z "$SSH_AGENT_PID" ] || echo " (A)"
|
|
|
|
}
|
2017-05-19 17:06:37 +02:00
|
|
|
prompt_status() {
|
2017-02-09 11:00:03 +01:00
|
|
|
if [ "$?" = "0" ]
|
2018-10-22 23:09:42 +02:00
|
|
|
then echo "$"
|
|
|
|
else echo "%"
|
2017-02-09 11:00:03 +01:00
|
|
|
fi
|
|
|
|
}
|
2018-10-22 23:09:42 +02:00
|
|
|
BOLD="\001$(tput bold)\002"
|
|
|
|
GREEN="\001$(tput setaf 2)\002"
|
|
|
|
RESET="\001$(tput sgr0)\002"
|
2018-11-30 10:01:33 +01:00
|
|
|
PS1="$BOLD[\t]$RESET $GREEN\$(ks prompt_pwd)$RESET\$(ks prompt_git)\$(ks prompt_agent) \$(prompt_status) "
|
2017-05-19 17:06:37 +02:00
|
|
|
unset BOLD
|
2017-02-09 11:00:03 +01:00
|
|
|
unset GREEN
|
|
|
|
unset RESET
|
|
|
|
|
2017-02-09 21:07:45 +01:00
|
|
|
# Completion
|
2017-10-09 10:22:36 +02:00
|
|
|
_comp_git() {
|
|
|
|
local IFS=$'\n'
|
|
|
|
# $1 is the name of the command whose arguments are being completed
|
|
|
|
# $2 is the word being completed
|
|
|
|
# $3 is the word preceding the word being completed
|
|
|
|
|
|
|
|
# branch names
|
|
|
|
COMPREPLY=( $(git branch -a --format "%(refname:short)" | grep "^$2") )
|
|
|
|
|
|
|
|
# remotes
|
|
|
|
COMPREPLY+=( $(git remote | grep "^$2") )
|
|
|
|
|
2017-10-17 10:07:22 +02:00
|
|
|
# files
|
2018-06-28 13:53:00 +02:00
|
|
|
COMPREPLY+=( $(git ls-files -coz --exclude-standard "$2*" | tr '\0' '\n' | sed "s?\($2[^/]*\).*?\1?") )
|
2017-10-17 10:07:22 +02:00
|
|
|
|
2017-10-09 10:22:36 +02:00
|
|
|
# subcommands
|
|
|
|
if [ "$3" = "git" ]; then
|
|
|
|
COMPREPLY+=( $({ compgen -c "git-"; command ls /usr/libexec/git-core; } | sed -n 's/^git-//p' | grep "^$2") )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-02-09 21:07:45 +01:00
|
|
|
complete -c man
|
|
|
|
complete -cf sudo
|
2017-08-10 17:53:41 +02:00
|
|
|
complete -cf exec
|
2017-09-26 10:00:11 +02:00
|
|
|
complete -cf run
|
2017-10-20 10:01:25 +02:00
|
|
|
complete -o filenames -F _comp_git git
|
2017-02-09 21:07:45 +01:00
|
|
|
|
2017-08-30 11:53:45 +02:00
|
|
|
# history
|
|
|
|
export HISTCONTROL=ignorespace:erasedups
|
|
|
|
|
2017-02-09 11:00:03 +01:00
|
|
|
# Color ls
|
2019-03-11 10:40:04 +01:00
|
|
|
ls_() {
|
|
|
|
lr -1FGG "$@" | git column --mode=dense --padding=3
|
|
|
|
}
|
|
|
|
alias ls="ls_"
|
2019-01-22 16:37:13 +01:00
|
|
|
alias ll="lr -Fl1Ghov"
|
2017-02-09 11:00:03 +01:00
|
|
|
|
2018-10-08 13:34:50 +02:00
|
|
|
# There is only one vis
|
2018-06-28 13:53:00 +02:00
|
|
|
alias vim="vis"
|
|
|
|
alias vi="vis"
|
|
|
|
alias nano="vis"
|
2017-02-09 11:00:03 +01:00
|
|
|
|
|
|
|
# Ready for ssh'ing
|
|
|
|
alias agent='eval "$(ssh-agent)" && ssh-add'
|
2017-09-26 10:00:11 +02:00
|
|
|
alias unlock='gpg-connect-agent <<<bye'
|
2017-02-09 11:00:03 +01:00
|
|
|
|
2017-06-14 10:21:16 +02:00
|
|
|
alias stop-after-this-song="mpc single && mpc idle && mpc single"
|
|
|
|
|
2017-10-24 12:04:19 +02:00
|
|
|
alias morning="maintain && gitfetcher"
|
|
|
|
|
2018-06-28 13:53:00 +02:00
|
|
|
alias weechat="ssh -t weechat@Chatmachine abduco -A weechat"
|
2018-02-26 11:52:05 +01:00
|
|
|
alias bearchat="ssh -f -N -L localhost:9001:localhost:8001 weechat@Chatmachine"
|
|
|
|
|
2017-05-19 17:06:37 +02:00
|
|
|
go() {
|
2017-10-30 23:20:35 +01:00
|
|
|
dir="$(lr /home /data /etc -t '(name ~~ ".*" && prune || print) && type = d && !(name = ".git")' \
|
2017-05-19 17:06:37 +02:00
|
|
|
| fzf --height 10 \
|
|
|
|
)"
|
2017-02-09 11:00:03 +01:00
|
|
|
[ -n "$dir" ] && cd "$dir" || false
|
|
|
|
}
|
|
|
|
|
2017-09-26 10:00:11 +02:00
|
|
|
run() {
|
|
|
|
exec "$@" > /dev/null 2>&1 &
|
|
|
|
}
|
|
|
|
|
2018-06-28 13:53:00 +02:00
|
|
|
terminfo() {
|
|
|
|
infocmp -x | ssh $@ 'cat > $TERM.info && tic -x $TERM.info && rm $TERM.info'
|
|
|
|
}
|