dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

sessions.vim (1641B)


      1 let s:seshdir = $HOME.'/.vim/sessions/'
      2 function! sessions#SaveSession() abort
      3   silent call mkdir (s:seshdir, 'p')
      4   let name = input("Save as: ")
      5   if name == ""
      6     echo "\nNo name provided."
      7   else
      8     let seshfile = s:seshdir.name.".vim"
      9     execute "mksession! " . seshfile
     10     echo "\nSession saved: ".seshfile
     11   endif
     12 endfunction
     13 function! s:ListSessions() abort
     14   silent call mkdir (s:seshdir, 'p')
     15   let files = globpath(s:seshdir, '*', 0, 1)
     16   call filter(files, '!isdirectory(v:val)')
     17   return files
     18 endfunction
     19 function! s:ChooseSession() abort
     20   let files = <SID>ListSessions()
     21   if len(files) > 0
     22     let inputfiles = map(copy(files), 'index(files, v:val)+1.": ".v:val')
     23     let response = inputlist(inputfiles)
     24     if response > 0
     25       return files[response-1]
     26     else
     27       return ""
     28     endif
     29   else
     30     echo "No sessions available."
     31     return ""
     32   endif
     33 endfunction
     34 function! sessions#LoadSession() abort
     35   let session = <SID>ChooseSession()
     36   if session != ""
     37     execute 'source '.session
     38   else
     39     echo "\nNo session selected."
     40   endif
     41 endfunction
     42 function! sessions#DeleteSession() abort
     43   let sesh = <SID>ChooseSession()
     44   if sesh == ""
     45     echo "\nNo session selected"
     46     return 1
     47   endif
     48   let conf = confirm("Delete ".sesh."?", "&Yes\n&No\n", 2)
     49   if conf == 1
     50     if delete(sesh) == 0
     51       echom "Deleted ".sesh
     52     else
     53       echom "Couldn't delete ".sesh
     54     endif
     55   else
     56     echom "No action taken."
     57   endif
     58 endfunction
     59 function! sessions#CloseSession()
     60   bufdo! bwipeout
     61   cd
     62   if exists('g:loaded_tagbar') && g:loaded_tagbar == 1
     63     execute "TagbarClose"
     64   endif
     65   echom "Session closed."
     66 endfunction