-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions
115 lines (92 loc) · 2.37 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
###########
# GENERAL #
###########
dotfiles-up() {
cd ~/.dotfiles
git stash && git pull --rebase && git stash pop
cd -
}
dotfiles-edit() {
atom ~/.dotfiles
}
mkcd() {
mkdir -p "$*"
cd "$*"
}
ip() {
loc=$(ipconfig getifaddr en0)
pub=$(curl -s -S https://api.ipify.org)
echo "Local : ${loc:=-}"
echo "Public: ${pub:=-}"
}
ports() {
lsof -iTCP -sTCP:LISTEN -P
}
public-key() {
cat ~/.ssh/id_rsa.pub | tee >(pbcopy)
}
transfer() {
# check arguments
if [ $# -eq 0 ];
then
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1
fi
# get temporarily filename, output is written to this file show progress can be showed
tmpfile=$( mktemp -t transferXXX )
# upload stdin or file
file=$1
if tty -s;
then
basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
if [ ! -e $file ];
then
echo "File $file doesn't exists."
return 1
fi
if [ -d $file ];
then
# zip directory and transfer
zipfile=$( mktemp -t transferXXX.zip )
cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile
curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile
rm -f $zipfile
else
# transfer file
curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile
fi
else
# transfer pipe
curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile
fi
# cat output link
cat $tmpfile
# cleanup
rm -f $tmpfile
}
#######
# GIT #
#######
current-branch() {
# Print the current branch/SHA1; returns if not in a git repo
ref=$(git symbolic-ref HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
clean-branches() {
git remote prune origin
branches=$(git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}')
echo $branches
echo -n "Proceed cleaning the above branches?"
read
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo $branches | xargs git branch -d
fi
}
gdm() {
git diff --name-only master..$(current-branch)
}
# Tiqets functions
# . ~/.dotfiles/projects/tiqets/functions
# WeTransfer functions
. ~/.dotfiles/projects/wetransfer/functions