-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions
More file actions
140 lines (126 loc) · 4.24 KB
/
Copy pathfunctions
File metadata and controls
140 lines (126 loc) · 4.24 KB
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
# Update dotfiles
udot() {
cwd=$(pwd)
cd ~/.dotfiles/
info=$(git --no-pager log --pretty="%h by %an <%ae> on %cd" -1 --abbrev-commit)
local=$(git --no-pager log --pretty="%H" -1)
remote=$(git ls-remote origin | awk "/HEAD/ {print \$1}")
gstatus=$(git status --porcelain)
echo -e ' ____ ___ _____ _____ _ U _____ u ____ '
echo -e ' | _ \ \/ _ \ |_ " _| |" ___| ___ |"| \| ___"| / __"| '
echo -e ' | | | | | | | | | | U| |_ u |_"_| U | | | _|" <\___ \ '
echo -e ' | |_| |\.-,_| |_| | /| |\ \| _|/ | | \| |/__ | |___ u___) | '
echo -e ' |____/ u \_)-\___/ u |_| u |_| u/| |\u |_____| |_____| |____/ '
echo -e ' |||_ \\ _// \\\\_ ) ( \\,-.-,_ // \\\\ )( (__) '
echo -e ' (__)_) (__) (__) (__) (_) (_/ \_) (_/ (__) (__) (_/ \_) '
echo -e ''
echo -e "$info"
echo -e ""
if [ -z "$status" ]; then
echo -e "Local changes:"
echo -e "$gstatus"
echo -e ""
fi
if [ "$local" = "$remote" ]; then
echo "Already up to date :)"
else
echo -e "Updating..."
git pull
bin/dfm install
source ~/.dotfiles/aliases
source ~/.dotfiles/functions
cd $cwd
fi
echo -e ""
echo -e "Update submodules..."
cd ~/.dotfiles
git submodule init
git submodule update
cd ~
echo -e ""
tmux source-file ~/.tmux.conf > /dev/null 2>&1
}
# will attach to existing tmux session, create new if one does not exist or just start bash if there is no tmux available.
function ssht(){
ssh $* -t 'tmux a || tmux || /bin/bash'
}
#Docker: bash into running Docker container
dockersh() {
docker cp ~/.dotfiles/docker.bashrc $1:/.docker.bashrc
docker cp ~/.dotfiles/aliases $1:/.docker.aliases
docker cp ~/.dotfiles/functions $1:/.docker.functions
docker exec -it $1 bash --rcfile /.docker.bashrc
}
#Docker: Show Docker container logging
dockerlog() {
docker logs -f $1
}
#Docker: run docker security check
dockersecure() {
docker run -it --net host --pid host --cap-add audit_control -v /var/lib:/var/lib -v /var/run/docker.sock:/var/run/docker.sock -v /usr/lib/systemd:/usr/lib/systemd -v /etc:/etc --label docker_bench_security --rm docker/docker-bench-security
}
# wrk - a HTTP benchmarking tool - https://github.com/wg/wrk
function wrk() {
docker run --rm williamyeh/wrk --latency $1
}
# Simple calculator
function calc() {
local result="";
result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')";
# └─ default (when `--mathlib` is used) is 20
#
if [[ "$result" == *.* ]]; then
# improve the output for decimal numbers
printf "$result" |
sed -e 's/^\./0./' `# add "0" for cases like ".5"` \
-e 's/^-\./-0./' `# add "0" for cases like "-.5"`\
-e 's/0*$//;s/\.$//'; # remove trailing zeros
else
printf "$result";
fi;
printf "\n";
}
# Create a new directory and enter it
function mcd() {
mkdir -p "$@" && cd "$_";
}
# Run `dig` and display the most useful info
function digga() {
dig +nocmd "$1" any +multiline +noall +answer;
}
# Search in bash history
function his() {
history | grep --color=auto -i "$1";
}
# Decompress just about any compressed file format
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ] ; then
# NAME=${1%.*}
# mkdir $NAME && cd $NAME
case $1 in
*.tar.bz2) tar xvjf ../$1 ;;
*.tar.gz) tar xvzf ../$1 ;;
*.tar.xz) tar xvJf ../$1 ;;
*.lzma) unlzma ../$1 ;;
*.bz2) bunzip2 ../$1 ;;
*.rar) unrar x -ad ../$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 ;;
*.xz) unxz ../$1 ;;
*.exe) cabextract ../$1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}