A single-file bash script that makes editing and publishing IPFS content extremely simple.
It mounts the IPFS namespaces, drops you into your chosen MFS folder with a clear prompt, lets you edit normally, then publishes to any IPNS key when you type save.
- Three clean phases: Start → Edit → Publish/Cleanup
- Shows every important
ipfscommand withset -o xtrace - Optional interactive prompts (no arguments needed)
- Automatically restores your original working directory when done
- Early error checking and clean exits
- Works with any IPNS key and any MFS path
# 1. Save the script
curl -L https://gist.githubusercontent.com/.../ipfs-edit/raw/ipfs-edit -o ~/bin/ipfs-edit
# 2. Make it executable
chmod +x ~/bin/ipfs-edit
# 3. (Optional) Add ~/bin to PATH if not already there
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc# Recommended — interactive mode
ipfs-edit
# Quick mode — key only (path defaults to /<key>)
ipfs-edit public- Shows your available IPNS keys (
ipfs key list) - Mounts
/ipfs,/ipns,/mfs - Changes into your MFS folder
- Prefixes your normal prompt so you always know where you are
- You edit files normally with any tools
- Type
save→ publishes to the chosen key and exits - Type
exit(or Ctrl+D) → discards changes and cleans up
#!/bin/bash
# ipfs-edit — 3-part interactive IPFS MFS editor
# Usage: ipfs-edit ← interactive
# ipfs-edit <IPNS_KEY> ← path defaults to /<key>
# ipfs-edit <IPNS_KEY> <MFS_PATH>
# ──────────────────────────────────────────────────────────────
# Argument handling
# ──────────────────────────────────────────────────────────────
if [[ $# -eq 0 ]]; then
echo "=== Available IPNS keys ==="
ipfs key list | grep -v '^self$'
echo
read -r -p "Enter IPNS key name: " KEY
if [[ -z "$KEY" ]]; then
echo "Error: No key name entered." >&2
exit 1
fi
read -r -p "Enter MFS path (default: /$KEY): " MFS_PATH
[[ -z "$MFS_PATH" ]] && MFS_PATH="/$KEY"
elif [[ $# -eq 1 ]]; then
KEY="$1"
MFS_PATH="/$KEY"
elif [[ $# -eq 2 ]]; then
KEY="$1"
MFS_PATH="$2"
else
echo "Usage: ${0##*/} [IPNS_KEY] [MFS_PATH]" >&2
exit 1
fi
# Ensure path starts with slash
[[ $MFS_PATH == /* ]] || MFS_PATH="/$MFS_PATH"
# ──────────────────────────────────────────────────────────────
# Main script (executed directly)
# ──────────────────────────────────────────────────────────────
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
ORIGINAL_PWD="$(pwd)"
ORIGINAL_PS1="${PS1}"
RC_FILE="/tmp/ipfs-edit-rc.$$"
cat > "$RC_FILE" << 'EOF'
# Source user's .bashrc to get real PS1
[ -f ~/.bashrc ] && . ~/.bashrc
ORIGINAL_PS1="${PS1}"
ipfs-edit-start() {
echo "=== PART 1: IPFS Edit Started ==="
echo "MFS Path : $MFS_PATH"
echo "IPNS Key : $KEY"
command -v ipfs >/dev/null 2>&1 || { echo "Error: ipfs not in PATH"; exit 1; }
ipfs id >/dev/null 2>&1 || { echo "Error: IPFS daemon not running"; exit 1; }
(set -o xtrace; ipfs mount) >/dev/null 2>&1 || { echo "Failed to mount"; exit 1; }
(set -o xtrace; ipfs files mkdir -p "$MFS_PATH") 2>&1 || { echo "Failed to mkdir"; exit 1; }
if cd "/mfs${MFS_PATH}" 2>/dev/null; then
export PS1="(IPFS-edit:${MFS_PATH}) [save | exit]
${ORIGINAL_PS1}"
echo "You are now editing."
echo "Type: save → publish & exit"
echo " exit → discard & exit"
else
echo "Error: Could not cd to /mfs${MFS_PATH}"
exit 1
fi
}
save() {
echo "=== PART 2: Publishing ==="
CID=$(set -o xtrace; ipfs files stat --hash "$MFS_PATH")
[[ -z "$CID" ]] && { echo "Error: Could not read CID"; return 1; }
echo "CID: $CID"
(set -o xtrace; umount /ipns) 2>/dev/null || true
(set -o xtrace; ipfs name publish -k "$KEY" "$CID")
echo "Published successfully to key '$KEY'."
ipfs-cleanup
}
ipfs-cleanup() {
echo "=== PART 3: Cleanup ==="
(set -o xtrace; umount /ipfs /mfs /ipns) 2>/dev/null || true
export PS1="$ORIGINAL_PS1"
echo "IPFS edit session finished."
}
trap 'ipfs-cleanup' EXIT
ipfs-edit-start
EOF
env ORIGINAL_PS1="$ORIGINAL_PS1" ORIGINAL_PWD="$ORIGINAL_PWD" \
MFS_PATH="$MFS_PATH" KEY="$KEY" \
bash --rcfile "$RC_FILE" -i
cd "$ORIGINAL_PWD"
echo "Returned to original directory: $(pwd)"
rm -f "$RC_FILE"
else
echo "ipfs-edit functions loaded (sourced mode)."
fiSave the script above as ipfs-edit, make it executable, and drop it in ~/bin/ (or anywhere in your $PATH).
Enjoy the cleanest way to edit and publish IPFS content! 🚀
Just copy everything above and create the gist. Let me know if you want a shorter version or any tweaks before you publish it.