snblog

Read my ramblings about computers, Linux, math, video games and other interests/hobbies.

Manage multiple Neocities websites from the command line

Jul 11, 2025 - 2 minute read - Programming

The neocities-rubyexternal link utility works great for managing your Neocities websites from the terminal unless you have multiple websites you’d like to manage this way, since the official utility does not provide any methods to have multiple accounts logged in simulateously.

Some searching around led me to this issue on Githubexternal link which gave me enough information. It turns out that you can use this utility if you specify your website’s API key before running a command, as such:

1
NEOCITIES_API_KEY={Your API key} neocities

However, manually obtaining, storing and then retrieving your API keys every single time you want to do something with this utility is a bit of a pain. So, we’re going to do something about the last 2 points. You’re going to have to obtain your website’s API key manually. You can do this by simply logging into your Neocities account from the command line. The program will tell you your API key. For now, store this in a .txt file in the root of your website’s directory.

Storing the API key as plaintext probably isn’t ideal so we’ll encrypt it using gpg. We’ll do some symmetric encryption for our purposes as such:

1
gpg --symmetric api_key.txt

You’ll be prompted to enter a passphrase, which you’ll use to access the contents of this file whenever you decrypt it.

Finally, let’s create a shell script that’ll let us use the rest of the neocities program as usual. The only caveat with this is that you’ll have to wrap your commands in a string, but the rest of the functionality is the same.

neocities.sh
1
2
3
4
5
6
7
8
#! /bin/bash
if [ "$#" -ne 1 ]; then
    printf 'ERROR! Include your commands in a string!' >&2
    exit 1
else
    api_key=$(gpg --decrypt api_key.txt.gpg 2> /dev/null)
    NEOCITIES_API_KEY=$api_key $1
fi

Things to note:

  1. line 2 checks if you entered more than 1 argument.
    • i.e. if you use the script as such: ./neocities.sh neocities info you’ll get an error.
    • Use it instead as such: ./neocities.sh 'neocities info'.
  2. line 6 decrypts api_key.txt.gpg and stores the API key in a variable, which it uses in the following command.

Repeat for each of your Neocities websites, and everytime you want to do something with it from the command line, you can use this script!

Comments?

If you have any thoughts about this post, feel free to get in touch!