-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.zsh
More file actions
117 lines (99 loc) · 2.24 KB
/
functions.zsh
File metadata and controls
117 lines (99 loc) · 2.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
#!/usr/bin/env zsh
# Functions - Custom shell functions
# Create directory and cd into it
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Extract various archive formats
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
}
# Quick backup of a file
backup() {
cp "$1" "$1.backup-$(date +%Y%m%d-%H%M%S)"
}
# Find file by name in current directory
ff() {
find . -type f -iname "*$1*"
}
# Find directory by name in current directory
fd() {
find . -type d -iname "*$1*"
}
# Get current git branch
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Quick git commit with message
gcmsg_quick() {
git commit -m "$*"
}
# Quick git add and commit
gac() {
git add . && git commit -m "$*"
}
# Get weather
weather() {
curl "wttr.in/${1:-}"
}
# Quick notes
note() {
echo "$(date): $*" >> ~/notes.txt
echo "Note added!"
}
# Show notes
notes() {
if [ -f ~/notes.txt ]; then
cat ~/notes.txt
else
echo "No notes found"
fi
}
# Simple calculator
calc() {
echo "scale=2; $*" | bc
}
# Get public IP
myip() {
curl -s https://api.ipify.org
echo
}
# Port checker
port_check() {
lsof -i :"$1"
}
# System info
sysinfo() {
echo "Hostname: $(hostname)"
echo "OS: $(uname -s)"
echo "Kernel: $(uname -r)"
echo "Uptime: $(uptime)"
echo "Memory: $(free -h 2>/dev/null || vm_stat | head -n 2)"
echo "Disk: $(df -h / | tail -1)"
}
# Quick HTTP server
serve() {
local port="${1:-8000}"
python3 -m http.server "$port"
}
# Show most used commands
most_used() {
history | awk '{print $2}' | sort | uniq -c | sort -rn | head -20
}