initial code

master
fanta 4 years ago
parent 4a16ce67f0
commit e31960d9f1

16
n

@ -0,0 +1,16 @@
#!/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" && $editor $nDir/$1
Loading…
Cancel
Save