You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
786 B
Bash

#!/bin/bash
nDir="$HOME/.config/n"
#editor="/usr/bin/vim"
#editor="/usr/bin/emacs"
editor="/usr/bin/nano"
check_root(){ if [ "$(id -u)" == 0 ]; then echo "don't run n as root"; exit; fi }
create_nDir(){ [ ! -d "$nDir" ] && mkdir -p $nDir ; }
get_tagListRecentUseOrder(){ { nTags=$(ls -1t $nDir | tee /dev/fd/3 | wc -l); } 3>&1 ; }
create_tag(){ nDir="$1" ; tagName="$2" ; [ ! -f "$nDir/$tagName" ] && touch $nDir/$tagName ; }
check_tag(){ tagName="$1" ; [[ "$tagName" = "${tagName%[[:space:]]*}" ]] && echo 0 || echo 1 ; }
check_root ; create_nDir
[[ $# -eq 0 ]] && get_tagListRecentUseOrder
[[ $# -eq 1 ]] && [[ $(check_tag "$1") -eq 1 ]] && echo "bad tag name . Please try again without spaces." && exit
[[ $# -eq 1 ]] && create_tag "$nDir" "$1"
[[ $# -eq 1 ]] && $editor $nDir/$1