Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 81 lines (70 sloc) 2.4 KB
#!/usr/bin/env bash
#TODO: Break out into own binary, to be called in entriesrc/handlersrc instead
# Tool to save arbitrary things from the current clip to various locations
name() {
printf '\n' | dmenu -p "Save $1 as: " -l 1
}
doc() {
local result cover
read -r result
cover="$("/usr/local/share/dsearch/is" "$result")"
[[ $result ]] && "$TERMINAL" -c float -e /usr/local/bin/bookkeep mk "$result" -t "$1" -e vis -c "$cover"
if [[ -s $XDG_DATA_HOME/librarian/bin/$result ]]; then
curl -s "$2" > media/docs/"$result.$1"
fi
}
image() {
local result input
read -r result
[[ $result ]] && curl -s "$1" > "$HOME/media/pictures/$result"
if [[ -s "$HOME/media/pictures/$result" ]]; then
exiftool -overwrite_original -Comment="$1" "$HOME/media/pictures/$result"
fi
}
note() {
local result
read -r result
curl -s "$1" > "$XDG_CACHE_HOME"/notes/"$result"
}
save_feed() {
if ! grep "$1" "$XDG_DATA_HOME"/feedurls; then
printf '%s\n' "$1" >> "$XDG_DATA_HOME"/feedurls
updatefeeds
fi
}
lsw | while read -r w; do
case $(wname "$w") in
*browse*) sed -n -e 's/_SURF_URI(STRING) = "//p' <<< "$(xprop -id "$w")" | tr -d '"' | xclip -o -selection clipboard ;;
esac
done
[[ $1 ]] && input="$1" || input=$(xclip -o -selection clipboard)
if grep "github" <<< "$input"; then
result=$(printf '%s\n%s\n' "Save" "Clone" | dmenu -p "Github: ")
[ $result ] || exit 0
if [[ $result == "Clone" ]]; then
cd $HOME/code
"$TERMINAL" -c float -g 45x4+20+20 -e git clone "$input"
cd "${input##*/}"
"$TERMINAL" &
exit 0
fi
fi
if grep "youtu" <<< "$input"; then
exec /usr/local/share/dsearch/youtube/savepl "$input"
fi
[[ $input ]] && case $(content-type "$input") in
*text/plain*) name "note" | note "$input" ;;
*image*) name "picture" | image "$input" ;;
*djvu*) name "document" | doc "djvu" "$input" ;;
*epub*) name "document" | doc "epub" "$input" ;;
*pdf*) name "document" | doc "pdf" "$input" ;;
*video*) exec "$XDG_DATA_HOME/youtube/savepl" "$input" ;;
*application/atom*) save_feed "$input" ;;
*application/rss*) save_feed "$input" ;;
*)
items=( "git - " "error - " "keyboards - " "linux - "
"main - " "programming - " "electronics - " )
result=$(printf '%s\n' "${items[@]}" | dmenu -p "Save bookmark: ")
[[ $result ]] && printf '%s' "$input" > "$XDG_DATA_HOME/bookmark/$result"
;;
esac
You can’t perform that action at this time.