-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_functions.tmpl
86 lines (77 loc) · 2.51 KB
/
dot_functions.tmpl
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
# Clean Debian packages
apt-clean() {
sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove
}
# Create a new directory and enter it
mkd() {
mkdir -p "$@" && cd "$@"
}
# Print README file
readme() {
for readme in {readme,README}.{md,MD,markdown,mkd,txt,TXT}; do
if [[ -x "$(command -v glow)" ]] && [[ -f "$readme" ]]; then
mdv "$readme"
elif [[ -f "$readme" ]]; then
cat "$readme"
fi
done
}
# Weather
weather() {
curl -s "https://wttr.in/${1:-Ponorogo}?m2F&format=v2"
}
# Get an information of IP address
ip-address() {
curl -s -H "Accept: application/json" "https://ipinfo.io/${1:-}" | jq "del(.loc, .postal, .readme)" || \
curl -s -H "Accept: application/json" "https://am.i.mullvad.net" | jq "del(.longitude, .latitude, .mullvad_exit_ip, .blacklisted)"
}
# Incognito mode
incognito() {
unset HISTFILE
if [ -x "$(command -v tmux)" ]; then
tmux set-option window-status-current-format "#[fg=brightwhite,bg=#b487b4] #I #[fg=brightwhite,bg=#966396] #W "
fi
}
# Git commit browser
fshow() {
local commit_hash="echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
local view_commit="$commit_hash | xargs -I % sh -c 'git show --color=always % | diff-so-fancy'"
git log --color=always \
--format="%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" "$@" | \
fzf --no-sort --tiebreak=index --no-multi --reverse --ansi \
--header="enter to view, alt-y to copy hash" --preview="$view_commit" \
--bind="enter:execute:$view_commit | less -R" \
--bind="alt-y:execute:$commit_hash | xclip -selection clipboard"
}
# Remove all commit in Git
git-remove-all-commit() {
local branch
branch=$(git symbolic-ref --short HEAD)
echo -e "\nDo you want to remove all your commit in \033[1m$branch\033[0m branch? [Y/n] "
read -r response
case "$response" in
[yY][eE][sS]|[yY])
git checkout --orphan latest_branch
git add -A
git commit -am "Initial commit"
git branch -D "$branch"
git branch -m "$branch"
echo -e "\nTo force update your repository, run this command:\n\n git push -fu origin $branch"
;;
*)
echo "Cancelled."
;;
esac
}
# Start PHP server
phpserver() {
local ip=localhost
local port="${1:-4000}"
php -S "${ip}:${port}"
}
# Start Python server
pythonserver() {
python -m http.server 3999 --directory ~/Public/wwwroot
}