1
0
mirror of https://github.com/pcvolkmer/vim-fugistate.git synced 2025-04-19 15:26:50 +00:00

Initial import

This commit is contained in:
Paul-Christian Volkmer 2022-01-09 06:43:55 +01:00
commit ed8a9ecda5
4 changed files with 122 additions and 0 deletions

19
LICENSE Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2022 Paul-Christian Volkmer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

35
README.md Normal file
View File

@ -0,0 +1,35 @@
# vim-fugistate
## Usage
This simple plugin provides a function which returns the name of current file with git status if available using
[vim-fugitive](https://github.com/tpope/vim-fugitive) and is intended for statusline integration.
```vim
:echo FugiState()
```
It will show something like `main.c [ M]` for modified file `main.c`.
For example, to show the filename with git status using [lightline.vim](https://github.com/itchyny/lightline.vim),
configure as follows.
```vim
let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'readonly', 'filenamestatus', 'modified' ] ]
\ },
\ 'component_function': {
\ 'filenamestatus': 'FugiState'
\ },
\ }
```
### Filename configuration
The plugin provides `g:fugistate_expand_filename` to modify the value the filename should be expanded to.
Default value is set to `'%:t'` and will show filename without path. Use available values like `'%:p'` for full path
or `''` to use `@%` for directory/filename relative to current working directory.
## License
This software is released under the MIT License, see LICENSE.

46
autoload/fugistate.vim Normal file
View File

@ -0,0 +1,46 @@
" Filename: plugin/fugistate.vim
" Author: Paul-Christian Volkmer <code@pcvolkmer.de>
" License: MIT License
let s:filename_status = ''
function! fugistate#update()
if empty(@%)
let s:filename_status = ''
return
endif
if empty(g:fugistate_expand_filename)
let filename = expand(@%)
else
let filename = expand(g:fugistate_expand_filename)
endif
try
if ! FugitiveIsGitDir()
let s:filename_status = filename
return
endif
let gitstatus = FugitiveExecute('status', '-s', @%)
if gitstatus.exit_status != 0 || empty(gitstatus.stdout[0])
let s:filename_status = filename
return
endif
let s:filename_status = filename . " [" . gitstatus.stdout[0][0:1] . "]"
catch
let s:filename_status = filename
endtry
endfunction
function! fugistate#filename_status()
return s:filename_status
endfunction

22
plugin/fugistate.vim Normal file
View File

@ -0,0 +1,22 @@
" Filename: plugin/fugistate.vim
" Author: Paul-Christian Volkmer <code@pcvolkmer.de>
" License: MIT License
if exists('g:loaded_fugistate') || v:version < 800
finish
endif
let g:loaded_fugistate = 1
if ! exists('g:fugistate_expand_filename')
let g:fugistate_expand_filename = '%:t'
endif
augroup FugiState
autocmd!
autocmd BufEnter,BufWritePost,FocusGained * :call fugistate#update()
autocmd User FugitiveChanged :call fugistate#update()
augroup END
function! FugiState()
return fugistate#filename_status()
endfunction