Skip to content

Instantly share code, notes, and snippets.

@jcenters
Created October 16, 2019 14:38
Show Gist options
  • Save jcenters/9a8aeae2a55e1e58e92d3403711eb41d to your computer and use it in GitHub Desktop.
Save jcenters/9a8aeae2a55e1e58e92d3403711eb41d to your computer and use it in GitHub Desktop.
Link Handler for the Mac
#!/usr/bin/env sh
# Feed script a url or file location.
# If an image, it will view in the default image view (probably Preview),
# if a video or music file, it will view in mpv
# otherwise it opens link in browser.
# If no url given. Opens browser. For using script as $BROWSER.
[ -z "$1" ] && { "$BROWSER"; exit; }
case "$1" in
*mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*)
mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet "$1" >/dev/null 2>&1 & ;;
*png|*jpg|*jpe|*jpeg|*gif)
curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///")" && open "/tmp/$(echo "$1" | sed "s/.*\///")" >/dev/null 2>&1 & ;;
*mp3|*flac|*opus|*mp3?source*)
# cd ~/Podcasts && curl -LO "$1" >/dev/null 2>&1 & ;;
mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) --player-operation-mode=pseudo-gui -quiet "$1" >/dev/null 2>&1 & ;;
*)
if [ -f "$1" ]; then "$TERMINAL" -e "$EDITOR $1"
else "$BROWSER" "$1" >/dev/null 2>&1 & fi ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment