-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfunctions.sh
87 lines (72 loc) · 2.11 KB
/
functions.sh
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
#!/usr/bin/env bash
# These should work with both bash and zsh
#
# To use these, put 'source /path/to/this/repo/functions.sh'
# in your shell profile
#
# these use a bunch of common-ish shell tools
# to interact with the hpi query JSON API
# jq: https://github.com/stedolan/jq
# fzf: https://github.com/junegunn/fzf
# helpers used across multiple functions
alias mpv-from-stdin='mpv --playlist=- --no-audio-display --msg-level=file=error'
filter_unique() {
awk '!seen[$0]++'
}
###################
# my.listenbrainz
###################
scrobbles() {
hpi query my.listenbrainz.export.history -s "$@"
}
scrobble-describe() {
jq -r '"\(.listened_at) \(.artist_name) - \(.track_name)"'
}
##########
# my.mpv
##########
# functions to replay music I've listened to recently
mpv-recent() {
local args=()
if [[ -n "$1" ]]; then
args+=("--limit" "$1")
fi
hpi query my.mpv.history_daemon.history --order-type datetime --reverse -s "${args[@]}"
}
mpv-recent-path() {
mpv-recent "$1" | jq -r .path
}
alias replay='mpv-recent-path 1 | mpv-from-stdin'
# requires https://github.com/purarue/exists, https://github.com/purarue/pura-utils
replay-recent() {
mpv-recent-path "$1" | exists | head -n "${1:-$LINES}" | unique | fzf | mpv-from-stdin
}
##########
# my.zsh
##########
# jq later to preserve newlines in commands
alias zsh-unique="hpi query -s my.zsh.history | jq '.command' | filter_unique | jq -r"
alias zsh-unique-fzf='zsh-unique | fzf'
############
# my.trakt
############
# e.g. trakt-movies --recent 4w | trakt-describe-movie
trakt-movies() {
hpi query 'my.trakt.export.history' -s "$@" | trakt-filter-movies
}
# e.g. trakt-episodes --recent 4w | trakt-describe-episode
trakt-episodes() {
hpi query 'my.trakt.export.history' -s "$@" | trakt-filter-episodes
}
trakt-filter-movies() {
jq 'select(.media_type == "movie")'
}
trakt-filter-episodes() {
jq 'select(.media_type == "episode")'
}
trakt-describe-movie() {
jq -r '"\(.media_data.title) (\(.media_data.year))"'
}
trakt-describe-episode() {
jq -r '"\(.media_data.show.title) (\(.media_data.show.year)) - S\(.media_data.season)E\(.media_data.episode) \(.media_data.title)"'
}