-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
97 lines (82 loc) · 2.66 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
86
87
88
89
90
91
92
93
94
95
96
97
# Create a new directory and enter it
function md() {
mkdir -p "$@" && cd "$@"
}
# determines if the git branch you are on is clean or dirty
git_prompt() {
if ! git rev-parse --git-dir >/dev/null 2>&1; then
return 0
fi
# Grab working branch name
git_branch=$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p')
# Clean or dirty branch
if git diff --quiet 2>/dev/null >&2; then
git_color="${c_git_clean}"
else
git_color=${c_git_dirty}
fi
echo " [$git_color$git_branch${c_reset}]"
}
# Commit message without quotes prefix required - didn't use much anyway, seems to clash with zimfw
# function c() { git commit -m "$*"; }
# function c.() {
# git add --all
# git commit -m "$*"
# }
# Find pid of processes listening on specified port
function pidport() { lsof -i tcp:$*; }
# Generate git ignore file boilerplate from gitignore.io api
function gi() { curl -L -s https://www.gitignore.io/api/$@; }
# ssh into ansible remote clients by hostname instead of raw IP address
an-ssh() {
if [ -z "$1" ]; then
echo "No hostname specified"
echo "usage: an-ssh [hostname]";
return 1;
fi
HOSTFILE=`find ~/.ansible/hosts`
HOST=`cat $HOSTFILE | grep "$1" | cut -d " " -f2 | cut -d "=" -f2`
ANSIBLE_USER=`cat $HOSTFILE | grep "$1" | cut -d " " -f3 | cut -d "=" -f2`
PORT=`cat $HOSTFILE | grep "$1" | cut -d " " -f4 | cut -d "=" -f2`
command echo "hostfile found: $HOSTFILE"
command echo "host found: $HOST, port: $PORT"
command echo "connecting as $ANSIBLE_USER to $HOST on port $PORT"
command ssh "$ANSIBLE_USER@$HOST" -p "$PORT"
}
# server the current directory on defined port, 3000 by default
function serve {
port="${1:-3000}"
ruby -run -e httpd . -p $port
}
jira-ref-from-branch-name() {
git branch | grep '*' | grep -o '\w\+-\d\+'
}
jira-prefixed-commit() {
if [ -z "$*" ]; then
echo "No commit message supplied, aborting commit." && return 1
fi
local prefix=$(jira-ref-from-branch-name)
[ -n "$prefix" ] && prefix="$prefix:"
echo "git commit -m $prefix $@"
git commit -m "$prefix $@"
}
toggle-alacritty-opacity() {
## If alacritty.yml does not exist, raise an alert
[[ ! -f ~/dotfiles/alacritty.yml ]] && \
notify-send "alacritty.yml does not exist" && exit 0
## Fetch background_opacity from alacritty.yml
opacity=$(awk '$1 == "background_opacity:" {print $2; exit}' \
~/dotfiles/alacritty.yml)
## Assign toggle opacity value
case $opacity in
1)
toggle_opacity=0.7
;;
*)
toggle_opacity=1
;;
esac
## Replace opacity value in alacritty.yml
sed -i -- "s/background_opacity: $opacity/background_opacity: $toggle_opacity/" \
~/dotfiles/alacritty.yml
}