Skip to content

Instantly share code, notes, and snippets.

@echometerain
Created January 1, 2025 03:24
Show Gist options
  • Save echometerain/835f0c5b06476469c99b49af7667b284 to your computer and use it in GitHub Desktop.
Save echometerain/835f0c5b06476469c99b49af7667b284 to your computer and use it in GitHub Desktop.
Grab the newest xkcd and display it using kitty
# assuming you use NetworkManager
if [ "$(nmcli networking connectivity check)" != "none" -a ! -z "${KITTY_PID+x}" ]; then
XKCD_JSON="$(curl -s https://xkcd.com/info.0.json)"
NUM="$(echo $XKCD_JSON | jq -r '.num')"
# suppresses error when file does not exist
if [ "$(cat ~/.last_xkcd 2>/dev/null)" != "$NUM" ]; then
echo $NUM > ~/.last_xkcd
echo $XKCD_JSON | jq -r '.safe_title'
kitten icat --align left "$(echo $XKCD_JSON | jq -r '.img')"
echo $XKCD_JSON | jq -r '.alt'
else
fortune
fi
else
fortune
fi
@echometerain
Copy link
Author

Tmux version:

if [ "$(nmcli networking connectivity check)" != "none" -a ! -z "${KITTY_PID+x}" ]; then
    XKCD_JSON="$(curl -s https://xkcd.com/info.0.json)"
    NUM="$(echo $XKCD_JSON | jq -r '.num')"
    if [ "$(cat ~/.last_xkcd 2>/dev/null)" != "$NUM" ]; then
        echo $NUM > ~/.last_xkcd
        echo $XKCD_JSON | jq -r '.safe_title'
        kitten icat --align left "$(echo $XKCD_JSON | jq -r '.img')"
        echo $XKCD_JSON | jq -r '.alt'
        TMUX="blocked"
    fi
fi

if [ "$TMUX" = "" ]; then
    if [ ! $(pidof kitty | grep " ") -a "$(pidof tmux)" != "" ]; then
        tmux attach-session
    else
        tmux
    fi
elif [ "$TMUX" != "blocked" ]; then
    fortune
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment