Guest User

Untitled

a guest
Sep 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 1.39 KB | None | 0 0
  1. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. " for screen use
  3. " opened in another screen? lets not play where's waldo anymore!
  4. " this will politely tell me which screen's window it is open in so that I may
  5. " go close it if I want, but still provide me the normal options
  6. " this may need paths and command tweaked for your flavor of linux, but it
  7. " is a great start for most.
  8. "
  9. augroup NoSimultaneousEdits
  10.     autocmd!
  11.     autocmd SwapExists * :call PrintScreenWindow()
  12. augroup END
  13.  
  14. "autocmd Bufwritepre,filewritepre  * :set fileformat=unix
  15. set ff=unix
  16.  
  17.  
  18. function! PrintScreenWindow ()
  19.   let fname = expand("%:p")
  20.   " fix fname here, remove the path and leave only the filename/basename
  21.   let fname =  fnamemodify(fname, ':t')
  22.   " you might have to fix your path to lsof
  23.   let my_command = "/usr/sbin/lsof | grep '" . fname . ".swp' | grep " . $USER . " | sed -n 's/^vim\\? \\+\\([0-9]\\+\\).*$/\\1/p' "
  24.   let result = substitute(system(my_command), '\n','','')
  25.   if result
  26.     let my_cmd2 = "cat /proc/" . result . "/environ | xargs -0 echo | sed -n 's/.*WINDOW=\\([0-9]*\\).*/\\1/p' "
  27.     let res2 = substitute(system(my_cmd2), '\n','','')
  28.     if res2 || res2 == '0'
  29.       echo 'This file is already opened in window: ' . res2
  30.     else
  31.       echo "command failed: " . my_cmd2
  32.     endif
  33.   else
  34.     echo my_command . " : cmd failed"
  35.   endif
  36. endfunction
Add Comment
Please, Sign In to add comment