-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbashrc_ext
107 lines (86 loc) · 2.6 KB
/
bashrc_ext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
### Repo Naming
source ~/.git-prompt.sh
# Retrieve the current git repository
function __git_repo {
git remote -v 2> /dev/null | grep push | sed s/\\.git.*/""/g | sed s/".*\/"//g
}
# Set the colors of PS1 and the name of the current repo/branch
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;31m\]$(__git_ps1 "@%s")\n\[\033[38;5;202m\]\[\033[00m\]\$ '
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM=auto
export GIT_PS1_SHOWCOLORHINTS=1
export PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
export PROMPT_COMMAND='__git_ps1 "\n\u@\h\[\033[01;34m\]\w\[\033[00m\]" "\n\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[\033[00m\]\$ "'
### Useful functions
# Updated cd function
function cd () {
local -ri n=${#*};
if [ $n -eq 0 -o -d "${!n}" -o "${!n}" == "-" ]; then
builtin cd "$@";
else
local e="s:\.\.\.:../..:g";
builtin cd "${@:1:$n-1}" $(sed -e$e -e$e -e$e <<< "${!n}");
fi
}
declare -A project_paths
CDP_CONFIG_FILE="${HOME}/.cdp.config"
if [ -f $CDP_CONFIG_FILE ]; then
# Load the cdp.config file
source ~/.cdp.config
else
# Load a default setting
project_paths["home"]="$HOME"
fi
# cdp - change directory to map of paths
function get_project_path_keys() {
keys=""
for key in "${!project_paths[@]}"; do
keys="$keys $key"
done
echo $keys
}
function cdp() {
if [ ! -f $CDP_CONFIG_FILE ]; then
echo "You do not have a configuration file: ~/.cdp-config"
fi
if [[ $# -eq 0 ]] ; then
echo "Pass one of the project shorthands as first argument"
for key in "${!project_paths[@]}"; do
echo " $key"
done
return 1
fi
base_path=${project_paths["$1"]}
if [ "$base_path" = "" ]; then
echo "No path defined for '$1'"
return 1;
fi
expanded_path=$(readlink -f "$base_path")
[ $# == 1 ] && cd $expanded_path || cd $2
}
_cdp_options=$(get_project_path_keys)
_complete_cdp()
{
cur=${COMP_WORDS[COMP_CWORD]}
#echo
# echo -en "Cur: $cur\n"
#echo Comp word nr: $COMP_CWORD
#echo prev: $3
if [ "$COMP_CWORD" -le "1" ] ; then
# echo Options: $_cdp_options
COMPREPLY=( $(compgen -W "$(get_project_path_keys)" -- $cur) )
else
local project=${COMP_WORDS[1]}
#echo Project: $project
local base_path="${project_paths["$project"]}"
#echo Basepath: "${base_path}"
[ "${cur}" == "" ] && eval cur=${base_path}/${cur}
COMPREPLY=( $(compgen -S "/" -d "$cur") )
fi
}
#complete -F _cdp_complete cdp
complete -o nospace -F _complete_cdp cdp
#complete -o nospace -F _complete_cdp -- cdp
#complete -W "$_cdp_options" cdp