Skip to content

Instantly share code, notes, and snippets.

@manno
Created July 10, 2025 10:15
Show Gist options
  • Select an option

  • Save manno/eda4cea38f50509a5f3c25bd278e322c to your computer and use it in GitHub Desktop.

Select an option

Save manno/eda4cea38f50509a5f3c25bd278e322c to your computer and use it in GitHub Desktop.
vi-d
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 [-d <left-dir>] <right-dir>/<file> [<left-dir>]"
exit 1
fi
while getopts ":d:" opt; do
case $opt in
d)
left="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
shift $(expr $OPTIND - 1 )
right="$1"
if [ -z "$left" ]; then
left=${2:-.}
fi
if [ ! -e "$right" ]; then
echo "Error: '$right' does not exist."
exit 1
fi
if [ ! -d "$left" ]; then
echo "Error: '$left' is not a directory."
exit 1
fi
file=$(basename "$right")
nvim -d "$left"/"$file" "$right"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment