Reduce the amount of work done in shell and the hypotheses on gvim handling a server and such, make it work with any vim implementation

This commit is contained in:
Tissevert 2021-07-12 21:38:19 +02:00
parent 4f4afa90d0
commit 5f31ff4891
2 changed files with 22 additions and 12 deletions

View File

@ -1,11 +1,5 @@
#!/bin/sh
[ -n "${TITFICHE_VIM_INSTANCE}" ] || TITFICHE_VIM_INSTANCE="TITFICHE"
REMOTE=" --remote"
gvim --serverlist | grep -q "${TITFICHE_VIM_INSTANCE}" || REMOTE=''
EDITOR="gvim --servername ${TITFICHE_VIM_INSTANCE}${REMOTE}"
export TITFICHE_MODE=1
if [ -z "${TITFICHE_HOME}" ]
then
export TITFICHE_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}/titfiche"
@ -15,11 +9,8 @@ fi
if [ -n "${1}" ]
then
mkdir "${TITFICHE_HOME}"
$EDITOR "${1}"
else
ID="$(date "+%Y/%m/%d/%H:%M")"
mkdir -p "${TITFICHE_HOME}/${ID%/*}"
$EDITOR -c "normal A# /${ID} " -c 'startinsert!' "${TITFICHE_HOME}/${ID}.md"
mkdir -p "${TITFICHE_HOME}"
$EDITOR "${TITFICHE_HOME}" -c "call NewTitfiche()"
fi

View File

@ -1,8 +1,27 @@
if $TITFICHE_MODE
if exists("$TITFICHE_HOME") && expand('%:p') =~ $TITFICHE_HOME
function! NewTitfiche()
let dir = strftime("%Y/%m/%d")
call mkdir(dir, 'p')
let zId = dir . '/' . strftime("%H:%M")
edit `=zId . ".md"`
call append(0, "# /" . zId . " ")
normal 1G$
startinsert!
endfunction
function! MkLink(p)
call mkdir(fnamemodify(a:p, ':h'), 'p')
call system('ln ' . expand('%:S') . ' ' . fnamemodify(a:p, ':S'))
endfunction
command! -nargs=1 -complete=file_in_path Tag call MkLink(<f-args>)
set isfname+=:
set includeexpr=substitute(v:fname,'/','','')
cd $TITFICHE_HOME
nnoremap <C-l> "zciw(/<C-r>#)<Esc>%i[<C-r>z]<Esc>%
vnoremap <C-l> "zc(/<C-r>#)<Esc>%i[<C-r>z]<Esc>%
inoremap <C-l> (/<C-r>#)<Esc>%i[]<Left>
nnoremap <C-n> :call NewTitfiche()<CR>
nnoremap <C-t> :Tag<Space>
endif