-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
74 lines (63 loc) · 1.91 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
# Check if executable exists
is_executable() {
type "$1" >/dev/null 2>&1
}
# Add to path
prepend-path() {
[ -d $1 ] && PATH="$1:$PATH"
}
# Switch long/short prompt
ps0() {
PS1="\[\033[38;5;226m\]"
PS1+='$ '
}
ps1() {
source "$DOTFILES_DIR"/.prompt
}
if [ "$(uname)" == "Darwin" ]; then #macOS
source "$DOTFILES_DIR/functions_macos"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then #Linux
source "$DOTFILES_DIR/functions_linux"
fi
# thefuck
## Temporarily disable thefuck for significant performance of .bash_profile
# eval $(thefuck --alias)
# random_saved_wallpaper
rsw() {
img_name=$(ls $WALLPAPER_DIR | sort -R | tail -n 1)
echo ${WALLPAPER_DIR}/${img_name}
$(set_wallpaper)
}
# random_unsplash_wallpaper
ruw() {
$(get_and_save_wallpaper)
img_name=$(ls -t $WALLPAPER_DIR | head -n 1)
$(set_wallpaper)
}
# Downlaod a wallpaper from unsplash and rename it
get_and_save_wallpaper() {
set_resolution
wget_output=$(wget --trust-server-names -nv -P $WALLPAPER_DIR "https://source.unsplash.com/featured/$display_resolution?wallpaper/$RANDOM" 2>&1) # download file and set wget_output from stderr
rename_wallpaper
}
# Rename wallpaper downloaded from Unsplash Source API. wget returns a filename with query parameters, this functions strips these query params
rename_wallpaper() {
IFS=' ' # set delimiter to space
read -ra strings <<<"$wget_output" # extract words from name to array
current_name=$(echo "${strings[5]}" | tr -d '"')
img_name=$(echo "${strings[5]}" | tr -d '"' | cut -d'?' -f1)".jpg" # echo $split_name
mv $current_name $img_name
}
# delete_unsplash_wallpaper
duw() {
img_name=$(ls -t $WALLPAPER_DIR | head -n 1)
rm -rf ${WALLPAPER_DIR}/${img_name}
}
# Fix common issues with random_unsplash_wallpaper
fix_random_unsplash_wallpaper() {
if [ ! -d $WALLPAPER_DIR ]; then
echo $WALLPAPER_DIR
mkdir -p $WALLPAPER_DIR
fi
}