-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions
85 lines (73 loc) · 1.51 KB
/
functions
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
__git_repo_name() {
cdup=$(git rev-parse --show-cdup 2> /dev/null)
if [ $? == 0 ]; then
if [ -z "$cdup" ]; then
cdup=.
fi
echo -n "("
name=$(git config --get remote.origin.url | sed -e 's/^.*[:\\/]\([^:.\\/]*\)\.git$/\1/')
if [ -n "$name" ]; then
echo -n $name
else
dir=$((cd $cdup; pwd) | tail -1)
echo -n $(basename $dir)
fi
echo ":"
fi
}
__virtualenv_name() {
if [[ -z "$VIRTUAL_ENV" ]]; then
echo ""
else
venv=$(echo "$VIRTUAL_ENV" | rev | cut -d/ -f1-2 | rev | cut -d/ -f1)
echo "[virtualenv: $venv] "
fi
}
cdg() {
cdup=$(git rev-parse --show-cdup 2> /dev/null)
r=$?
if [ $r == 0 ]; then
if [ -z "$cdup" ]; then
cdup=.
fi
cd $cdup/$1
else
echo "Not in a git repository"
return $r
fi
}
domainavailable() {
if whois $1 | grep "No match for" &> /dev/null; then
echo "$1 is available"
return 0
else
echo "$1 is not available"
return 1
fi
}
finddomain() {
for f in $@; do
domainavailable $f &> /dev/null && echo $f
done
}
# Autocomplete for op command
_op_complete() {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
basedir=$HOME/proyectos
opts=$(cd $basedir; find -maxdepth 2 -type d | cut -b 3-)
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _op_complete op
_inside_screen() {
[ "$STY" != "" ]
}
_screen_id() {
echo $STY | cut -d. -f 2-
}
ipfor() {
host $1 | cut -d ' ' -f 4
}
# vim:set syntax=sh:set ai: