Skip to content

[proposal]: live remote update while updating local file #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pwang2 opened this issue Sep 15, 2022 · 1 comment
Closed

[proposal]: live remote update while updating local file #236

pwang2 opened this issue Sep 15, 2022 · 1 comment

Comments

@pwang2
Copy link

pwang2 commented Sep 15, 2022

The motivation comes from when I have to work on different machines and update my vimrc file, the Gist -l and save to local file workflow sounds quite cumbersome to me. It would be much smoother if vimrc file can be downloaded from remote gist automatically then sourced when vimrc file is opened.

In current vim-gist, we already have the embed GistID: xxxx for updating. It would be great if we can using the same machanism to offer an option to automatically sync the remote gist file to local when open the file with an embeded GistID at the end of the file.

I have this poorman's implementation in my vimrc for a while. But I feel it would be great if we could have this in the plugin itself and use a simple configuration to opt in.

function! s:sync_gist()
  let b:fpath = expand('%:p')
  let b:fname = expand('%:t')
  let b:lastline = system('tail -n 1 '. b:fpath))
  if b:lastline =~ 'GistID'
    let b:gid = substitute(system('tail -n 1 '. b:fpath. " | awk -F': ' '{print $2}' ") ,'\n', '', 'g')
    let b:cmd = '%!curl -sSL -H "Cache-Control: no-cache" "https://gist.githubusercontent.com/xxx/'. b:gid. '/raw?t='. strftime('%s'). '"'
    call setreg('+', b:cmd)
    silent execute(b:cmd)

    if trim(getline(line('$'))) == trim(b:lastline)
      silent write
      if b:fname == 'init.lua' || b:fname == 'init-old.vim'"
        execute('source $MYVIMRC')
      endif
    else
      echoerr("Remote version not expected, reload disk version")
      execute(':e!')
    endif
  endif
endfunction

function! s:post_gist()
  if getbufinfo('%')[0].changed && getline('$') =~ "GistID" 
     execute "Gist" 
  endif
endfunction

  au BufReadPost  *                  call <SID>sync_gist()
  au BufWritePre  *                  call <SID>post_gist()

"GistID: xxxxxxxxxxx
@pwang2 pwang2 closed this as completed Nov 18, 2022
@pwang2
Copy link
Author

pwang2 commented Nov 18, 2022

switched to gist-paste command line.
https://github.com/dblevins/gistpaste

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant