[home]_________________________________________________________________[light]

#!/bin/bash

# Released into the Public Domain via Unlicense (2025).
# See: https://unlicense.org/

# nview is a straightforward script that saves the responses of command-line
# finger clients to a temporary file so that 'NFO Viewer' can display it.

# Why? Because I wanted to both highlight NFO Viewer and use it regularly:-)

# system-wide install .. : sudo install nview /usr/local/bin/  (OR)
# prompt before overwrite: sudo cp -i nview /usr/local/bin/

# For some information, please see:
# fingerverse@happynetbox.com
# https://640kb.neocities.org/fingerverse/index.html

# code is 100% LLM generated (DeepSeek)

# This script relies on the installation of "NFO Viewer" available at:
# https://github.com/otsaloma/nfoview
# https://otsaloma.io/nfoview/
# Also available on most system package managers (which is what I did)

# Version 2.2 : Change log (07may2025):
# ------------------------------------
# Added code to check for the existence of 'finger'

# Version 2.1 : Change log (03may2025):
# ------------------------------------
# me: changed default app from bfinger (my error) to finger
# LLM: added code to check if nfoview is installed
# me: minor editorial changes

# Version 2.0 : Change log (02may2025):
# ------------------------------------
# now accepts a second argument for piping commands
# better error handling
# temp files are always cleaned up, even if script crashes

# Version 1.0 : initial release (01may2025)

# Check for nfoview dependency
if ! command -v nfoview > /dev/null; then
  echo "Error: nfoview is not installed. Please install it first."
  exit 1
fi

# Check for finger dependency
if ! command -v finger > /dev/null; then
  echo "Error: finger is not installed. Install it via your package manager"
  echo "       (e.g., 'sudo apt install inetutils-finger')"
  exit 1
fi

# Check if an argument was provided
if [ -z "$1" ]; then
  echo ""
  echo "nview - view finger output in NFO Viewer with optional piping"
  echo ""
  echo "Usage: $0 user@domain.com [\"piping_command\"]"
  echo ""
  echo "Examples:"
  echo ""
  echo "  $0 @happynetbox.com"
  echo "  $0 user@happynetbox.com"
  echo "  $0 @plan.cat \"| head -n 20\""
  echo "  $0 @plan.cat \"| grep -E 'Sun|Fri|Tue'\""
  echo ""
  echo "Install:   chmod +x nview && sudo install nview /usr/local/bin"
  echo "Uninstall: sudo rm /usr/local/bin/nview"
  echo ""
  echo "Uses:     the standard 'finger' command (install via inetutils-finger)"
  echo "Requires: nfoview (https://otsaloma.io/nfoview/)"
  echo "Note:     Second argument is a shell pipeline (in quotes)"
  echo "Note:     Output saved to a temp .nfo file (auto-deleted)"
  echo ""
  echo "$(tput bold)Visit:    https://640kb.neocities.org/fingerverse for more clients$(tput sgr0)"
  echo ""
  exit 1
fi

# Use the exact input as the target
TARGET="$1"
PIPING_CMD="${2:-}"  # Optional piping command

# Create a temp file with .nfo extension
tmpfile=$(mktemp /tmp/finger_output.XXXXXX.nfo)
trap 'rm -f "$tmpfile"' EXIT  # Ensure cleanup on exit

# Process with optional piping
if [ -z "$PIPING_CMD" ]; then
  # Simple case - no piping
  finger "$TARGET" > "$tmpfile"
else
  # Piped processing
  eval "finger '$TARGET' $PIPING_CMD" > "$tmpfile"
fi

# Verify we got output
if [ ! -s "$tmpfile" ]; then
  echo "Error: No output generated (invalid target or filter?)"
  exit 1
fi

# Launch nfoview and wait for it to close
nfoview "$tmpfile"

# Cleanup is handled by trap


.----------------------------------. .--------------. .--------------------. |finger fingerverse@happynetbox.com|--| May 07, 2025 |--| 640kb.neocities.org| '----------------------------------' '--------------' '--------------------'