-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
170 lines (150 loc) · 4.19 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
# ############################################## #
# FONCTIONS #
# ############################################## #
function cheatsh {
curl "https://cheat.sh/${1}"
}
# Taken from Symfony installer
function output {
style_start=""
style_end=""
if [ "${2:-}" != "" ]; then
case $2 in
"success")
style_start="\033[0;32m"
style_end="\033[0m"
;;
"error")
style_start="\033[31;31m"
style_end="\033[0m"
;;
"info"|"warning")
style_start="\033[33m"
style_end="\033[39m"
;;
"heading")
style_start="\033[1;33m"
style_end="\033[22;39m"
;;
esac
fi
builtin echo -e "${style_start}${1}${style_end}"
}
function output_success {
output "${1}" 'success'
}
function output_heading {
output "${1}" 'heading'
}
function output_info {
output "${1}" 'info'
}
function output_warning {
output "${1}" 'warning'
}
function output_error {
output "${1}" 'error'
}
function sf
{
if [ -f bin/console ]; then
bin/console "$@"
elif [ -f app/console ]; then
app/console "$@"
else
echo "No console found"
fi
}
# colored man pages
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# Extraire automatiquement une archive
function extract()
{
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $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
}
# lecture colorée de logs
logview()
{
ccze -A < $1 | less -R
}
# lecture colorée de logs en directfunction logview()
logtail()
{
tail -f $1 | ccze
}
# source https://gist.github.com/nl5887/a511f172d3fb3cd0e42d
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
}
switch-php() {
sudo update-alternatives --set php /usr/bin/php$1
}
# Keep header line while doing a grep
# Usage: ps aux | hgrep ssh
hgrep() {
echo -n "\033[32m"; head -1; echo -n "\033[39m"; grep -i "$*"
}