-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.functions
More file actions
79 lines (68 loc) · 1.63 KB
/
.functions
File metadata and controls
79 lines (68 loc) · 1.63 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
# find shorthand
f () {
find . -name "$1"
}
# Start an HTTP server from a directory, optionally specifying the port
server () {
local port="${1:-8000}"
(sleep 2 && open "http://localhost:${port}") & disown
python3 -m http.server "${port}"
}
# Upload file to server and copy link to clipboard
scpp () {
local HOST="stkn.org"
local DIR="htdocs/static.stkn.org"
scp "$1" "$HOST:$DIR";
ssh "$HOST" chmod a+r "$DIR/$1"
echo "https://static.stkn.org/$1" | pbcopy;
echo "Copied to clipboard: https://static.stkn.org/$1"
}
# npm bump
bump () {
npm version "$1" -m "bump version to %s"
}
# docker clean
dcl () {
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
}
# ssh tunnel: tunnel <host> <destination port> <local port>
tunnel () {
echo "Forwarding $1:$2 to localhost:$3"
ssh -nNT -L "$3":localhost:"$2" "$1"
}
# generate password
pwgen () {
length=${1:-16}
openssl rand -base64 $length | tr -d '\n' | colrm $((++length))
}
# source python venv - walks up tree to find and activate virtual environment
svenv () {
# Deactivate current venv if active
if [ -n "$VIRTUAL_ENV" ]; then
deactivate 2>/dev/null
fi
CURRENT_DIR="$(pwd)"
FOUND=0
while [ "$(pwd)" != "/" ]; do
# Check for standard venv
if [ -f "venv/bin/activate" ]; then
source "venv/bin/activate"
FOUND=1
break
elif [ -f ".venv/bin/activate" ]; then
source ".venv/bin/activate"
FOUND=1
break
else
cd ..
fi
done
cd "$CURRENT_DIR"
if [ $FOUND -eq 1 ]; then
echo "✓ Activated virtual environment: $VIRTUAL_ENV"
else
echo "✗ No virtual environment found"
return 1
fi
}