~skiqqy/bin

61dcacdbbe43b8bd258000c4eff88d3ff9f10f0e — Stephen Cochrane 2 months ago 285ec76
Todo can now open in a term
1 files changed, 27 insertions(+), 5 deletions(-)

M todo
M todo => todo +27 -5
@@ 7,6 7,25 @@ main()
	# TODO: Consider saving dir locally for performance.
	wdir="$(find "$HOME" -regex '.*/todo' -type d 2> /dev/null | head -1)"
	[ -z "$wdir" ] && printf 'Please create a "todo" directory...\n' && return 1
	term= # Terminal to launch todo in, default is curr shell

	while getopts hs opt
	do
		case "$opt" in
			h)
				echo 'TODO. usage()'
				return
				;;
			s)
				term='st -e' # Run in new terminal
				;;
			*)
				echo 'TODO. usage()'
				return 1
				;;
		esac
	done
	shift "$((OPTIND-1))" # Get rid of parsed args

	# Change work dir.
	pushd "$wdir" || return 1


@@ 25,13 44,16 @@ main()
				done
				;;
			'')
				select open in *.md
				do
					$EDITOR "$open"
				done
				run="select open in *.md; do \$EDITOR \"\$open\"; done"
				if [ -n "$term" ]
				then
					$term env -C "$wdir" bash -c "$run" # Run in term
				else
					eval "$run" # eval is evil
				fi
				;;
			*)
				$EDITOR "$(basename "$1" .md).md"
				$term $EDITOR "$(basename "$1" .md).md" # I want splitting
				;;
		esac
	popd || return 1