Skip to content

Instantly share code, notes, and snippets.

@RaghavRao
Last active August 16, 2018 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RaghavRao/a08146cbc37ac246f6428e7c6b54d3c7 to your computer and use it in GitHub Desktop.
Save RaghavRao/a08146cbc37ac246f6428e7c6b54d3c7 to your computer and use it in GitHub Desktop.
Create a new script by executing "which".
#!/bin/bash
# Append to ~/.bashrc
# Usage:
# Default editor from /etc/alternatives/editor: $ nf python ~/scripy.py
# Custom editor: $ nf python ~/script.py vi
nf() {
STR=$( echo "#!"`which "$1"` )
if [ ! -f "$2" ]; then
echo $STR > "$2"
echo "" >> "$2"
if [ -z ${3+x} ]; then EDT="/etc/alternatives/editor +2"; else EDT="$3 +2"; fi
$EDT "$2"
chmod +x "$2"
else
echo "File already exists!"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment