-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
144 lines (120 loc) · 3.2 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
# Inspired by https://github.com/mathiasbynens/dotfiles/blob/main/.functions
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
# Create a ZIP archive of a folder
zipf () { zip -r "$1".zip "$1" ; }
# Extract most know archives with one command
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# find all files containg passed arg in current folder
qfind () { find . -iname "*$1*" ; }
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
function targz() {
local tmpFile="${@%/}.tar";
tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1;
size=$(
stat -f"%z" "${tmpFile}" 2> /dev/null; # macOS `stat`
stat -c"%s" "${tmpFile}" 2> /dev/null; # GNU `stat`
);
local cmd="";
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
# the .tar file is smaller than 50 MB and Zopfli is available; use it
cmd="zopfli";
else
if hash pigz 2> /dev/null; then
cmd="pigz";
else
cmd="gzip";
fi;
fi;
echo "Compressing .tar ($((size / 1000)) kB) using \`${cmd}\`…";
"${cmd}" -v "${tmpFile}" || return 1;
[ -f "${tmpFile}" ] && rm "${tmpFile}";
zippedSize=$(
stat -f"%z" "${tmpFile}.gz" 2> /dev/null; # macOS `stat`
stat -c"%s" "${tmpFile}.gz" 2> /dev/null; # GNU `stat`
);
echo "${tmpFile}.gz ($((zippedSize / 1000)) kB) created successfully.";
}
# Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
# Use Git’s colored diff when available
hash git &>/dev/null;
if [ $? -eq 0 ]; then
function diff() {
git diff --no-index --color-words "$@";
}
fi;
# Set the volume to 0 (mute) and then lock the screen.
function afk() {
osascript -e "set Volume 0";
open -a ScreenSaverEngine;
}
# Open a specified folder in IntelliJ (CE or Ultimate)
function idea() {
PATH_TO_OPEN=''
IS_CE=0
OPTIND=1
while getopts ":ch" opt; do
case "${opt}" in
c)
IS_CE=1
;;
*)
cat<<HELP_USAGE
Usage: idea [OPTIONS] [PATH]
Open the specified PATH in IntelliJ Idea. If no PATH is specified, use current path.
Options:
-c Open the Community Edition.
-h Print usage
HELP_USAGE
return 1
esac
done
if [ "$IS_CE" = 1 ]; then
PATH_TO_OPEN="${2:-''}"
IDEA_APP_PATH="/Applications/IntelliJ IDEA CE.app/"
else
PATH_TO_OPEN="${1:-''}"
IDEA_APP_PATH="/Applications/IntelliJ IDEA.app/"
fi
open -a "$IDEA_APP_PATH" $PATH_TO_OPEN
#open -a "/Applications/IntelliJ IDEA.app/"
return 0
}
function what-the-port() {
echo "Looking for port ${1}..."
lsof -i -P | grep LISTEN | grep :$1
}