-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
51 lines (45 loc) · 1.84 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
#!/usb/bin/env zsh
################################################################################
# Information
################################################################################
# Maintained by William W. Marx (m94@marx.sh)
# 🄯 Copyleft 2022, All Wrongs Reserved
# https://github.com/williamwmarx/shell
# ------------------------------------- ip ------------------------------------
# Fetch either local or public IP addresses
# -l --local Fetch local IP address
# -p --public Fetch public IP address
function ip() {
case $1 in
-l|--local) pconfig getifaddr en0;;
-p|--public) curl -fSSL https://ipecho.net/plain ; echo;;
*) echo -e "Fetch local and public IP addresses\n\nUsage: ip [OPTIONS]\n\nOptions:";
echo -e " -l, --local\tLocal IP address\n -p, --public\tPublic IP address\n";;
esac
}
# ------------------------------------ mkd ------------------------------------
# Create a new directory and enter it
function mkd() {
mkdir -p "$@" && cd "$_";
}
# ---------------------------------- dataurl ----------------------------------
# Create a data URL from a file
function dataurl() {
local mimeType=$(file -b --mime-type "$1");
if [[ $mimeType == text/* ]]; then
mimeType="${mimeType};charset=utf-8";
fi
echo "data:${mimeType};base64,$(openssl base64 -in "$1" | tr -d '\n')";
}
# ------------------------------------ cdf ------------------------------------
# Change working directory to the top-most Finder window location (macOS only)
if [ $(uname -s) = "Darwin" ]; then
function cdf() { # short for `cdfinder`
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
}
fi
# --------------------------------- expandurl ---------------------------------
# Take a shortened url and expand its final destination
function expandurl() {
curl -sIL $1 | rg -Po "(?<=location: ).+" | tail -1;
}