Skip to content

Commit c22b183

Browse files
author
adigitoleo
committed
First commit
0 parents  commit c22b183

File tree

5 files changed

+304
-0
lines changed

5 files changed

+304
-0
lines changed

LICENSE

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BSD Zero Clause License
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
4+
5+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6+

README.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Mellow Statusline
2+
3+
### A minimal statusline for (neo)vim, best served with [mellow]
4+
5+
![palette](./img/colorscheme.png)
6+
7+
`Plug 'adigitoleo/vim-mellow-statusline'`
8+
9+
<!-- vim-markdown-toc GFM -->
10+
11+
* [Screenshots](#screenshots)
12+
* [Installation](#installation)
13+
* [Usage](#usage)
14+
* [Customization](#customization)
15+
* [Miscellaneous](#miscellaneous)
16+
17+
<!-- vim-markdown-toc -->
18+
19+
TODO:
20+
- Outdated plugin notifier?? wishlist, would want to run async git fetches
21+
- Some filetype and input hints, (including xkb-switch indicator?)
22+
- vimtex stuff? maybe on wishlist
23+
24+
25+
## Screenshots
26+
27+
Taken on alacritty with LiberationMono font:
28+
29+
*ADD SCREENSHOTS*
30+
31+
## Installation
32+
33+
If you use a vim plugin manager (recommended), consult the relevant
34+
documentation. Here are some links to popular plugin managers:
35+
- [Pathogen]
36+
- [NeoBundle]
37+
- [Vundle]
38+
- [vim-plug]
39+
40+
For manual installation, download the files from GitHub and put both the
41+
`autoload` and `plugin` folders inside:
42+
- `~/.vim/` (vim users)
43+
- `~/.config/nvim/` (neovim users)
44+
45+
46+
## Usage
47+
48+
After installation, the statusline should work upon the next restart of
49+
(neo)vim. The statusline uses the User1-9 highlight groups by default (see
50+
`:help hl-User1..9`). If you want to use the recommended [mellow] colorscheme,
51+
remember to load it first. Additionally, add the following to your config file
52+
(see `:help vimrc`):
53+
54+
```vim
55+
:set termguicolors
56+
:let g:mellow_user_colors = 1
57+
:colorscheme mellow
58+
```
59+
60+
Alternatively you can define arbitrary colors for the relevant highlight
61+
groups (subject to [terminal compatibility]).
62+
63+
64+
### Customization
65+
66+
The colors and text hints for different vim-modes can be configured by
67+
overwriting the `g:mellow_mode_map` dictionary. The default values can be found
68+
in `plugin/mellow_statusline.vim` (search for that variable).
69+
70+
The dictionary maps the first letter returned by `mode()` to both a color and a
71+
text string. See also `:help mode()` and `:help 'statusline'`.
72+
73+
74+
## Miscellaneous
75+
76+
After writing the [mellow] colorscheme, I wanted to integrate an [ALE]
77+
indicator into my statusline. The default statusline is necessarily basic, so I
78+
had previously used [airline] and later [lightline] for this purpose. Although
79+
they are both great plugins, I began to feel that they were a bit overkill for
80+
me. I experimented with writing my own statusline, inspired by various snippets
81+
and some minimalist statusline plugins like [moonfly-statusline] and
82+
[vim-statline]. This way, I could define a few optional highlight groups in
83+
[mellow] and simply use the `%N*` syntax for statusline colors.
84+
85+
86+
[NOTE]: # ( ------------ PUT ALL EXTERNAL LINKS BELOW THIS LINE ------------ )
87+
88+
[terminal compatibility]: https://gist.github.com/XVilka/8346728
89+
90+
[Pathogen]: https://github.com/tpope/vim-pathogen
91+
92+
[NeoBundle]: https://github.com/Shougo/neobundle.vim
93+
94+
[Vundle]: https://github.com/gmarik/vundle
95+
96+
[vim-plug]: https://github.com/junegunn/vim-plug
97+
98+
[mellow]: https://github.com/adigitoleo/vim-mellow
99+
100+
[ALE]: https://github.com/dense-analysis/ale
101+
102+
[airline]: https://github.com/vim-airline/vim-airline
103+
104+
[lightline]: https://github.com/itchyny/lightline.vim
105+
106+
[moonfly-Statusline]: https://github.com/bluz71/vim-moonfly-statusline
107+
108+
[vim-statline]: https://github.com/millermedeiros/vim-statline

autoload/mellow_statusline.vim

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2+
" Functions for vim-mellow-statusline components.
3+
" Maintainer: adigitoleo <[email protected]>
4+
" Version: 0.1
5+
"
6+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
7+
8+
9+
function! mellow_statusline#Mode(mode_map) abort
10+
" Mode indicator for the active (FIX) statusline.
11+
let l:mode = mode()
12+
let [mode_color, mode_text] = a:mode_map[l:mode]
13+
return join([mode_color, mode_text, '%*'])
14+
endfunction
15+
16+
17+
function! mellow_statusline#File() abort
18+
" Shorter file/buffer identifier.
19+
if &buftype != ''
20+
return expand('%:t')
21+
else
22+
return pathshorten(expand('%:~'))
23+
endif
24+
endfunction
25+
26+
27+
function! mellow_statusline#Flags() abort
28+
" File flags (modified, readonly).
29+
let l:flags = []
30+
if (&modifiable && &modified)
31+
call add(l:flags, '+')
32+
endif
33+
34+
if &readonly
35+
call add(l:flags, 'RO')
36+
endif
37+
38+
" Using join avoids adding extraneous spaces.
39+
return join(l:flags)
40+
endfunction
41+
42+
43+
function! mellow_statusline#GitBranch() abort
44+
" Parse git branch name from Fugitive.
45+
let l:gitbranch = exists("g:loaded_fugitive")?fugitive#statusline():""
46+
let l:gitbranch = substitute(l:gitbranch, '[Git(', '', '')
47+
let l:gitbranch = substitute(l:gitbranch, ')]', '', '')
48+
return l:gitbranch
49+
endfunction
50+
51+
52+
function! mellow_statusline#ALE() abort
53+
" Linter status, see https://github.com/dense-analysis/ale#faq-statusline
54+
if (exists('b:ale_enabled') && !b:ale_enabled)
55+
\ || (exists('g:ale_enabled') && !g:ale_enabled)
56+
return ''
57+
endif
58+
59+
if ale#engine#IsCheckingBuffer(bufnr())
60+
return '...'
61+
endif
62+
63+
let l:counts = ale#statusline#Count(bufnr())
64+
let l:num_errors = l:counts.error + l:counts.style_error
65+
let l:num_warnings = l:counts.total - l:num_errors
66+
67+
return printf('%dW %dE', num_warnings, num_errors)
68+
endfunction
69+
70+
71+
function! mellow_statusline#CheckIndent() abort
72+
" Mixed indent or bad expandtab warning.
73+
" See https://github.com/millermedeiros/vim-statline
74+
if !exists('b:mellow_indent_warning')
75+
let b:mellow_indent_warning = ''
76+
77+
if !&modifiable
78+
return b:mellow_indent_warning
79+
endif
80+
81+
let l:tabs = search('^\t', 'nw') > 0
82+
let l:spaces = search('^ \+', 'nw') > 0
83+
84+
if l:tabs && l:spaces
85+
let b:mellow_indent_warning = 'mixed indent'
86+
elseif l:spaces && !&expandtab
87+
let b:mellow_indent_warning = 'noexpandtab'
88+
elseif l:tabs && &expandtab
89+
let b:mellow_indent_warning = 'expandtab'
90+
endif
91+
endif
92+
return b:mellow_indent_warning
93+
endfunction

img/colorscheme.png

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/leon/gitdev/vim-mellow/img/colorscheme.png

plugin/mellow_statusline.vim

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2+
" Minimal statusline for (neo)vim, best served with the mellow colorscheme.
3+
" Maintainer: adigitoleo <[email protected]>
4+
" Version: 0.1
5+
"
6+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
7+
8+
9+
if exists('g:loaded_mellow_statusline')
10+
finish
11+
endif
12+
let g:loaded_mellow_statusline = 1
13+
14+
15+
if has("nvim")
16+
let s:normal = "nvim"
17+
elseif has("gui_running")
18+
let s:normal = "gvim"
19+
else
20+
let s:normal = "vim"
21+
endif
22+
23+
" Define mode colors and strings.
24+
let g:mellow_mode_map = get(g:, "mellow_mode_map",
25+
\{
26+
\ "n": ["%5*", s:normal ],
27+
\ "i": ["%6*", "insert"],
28+
\ "R": ["%8*", "r-mode"],
29+
\ "v": ["%7*", "visual"],
30+
\ "V": ["%7*", "v-line"],
31+
\ "\<C-v>": ["%7*", "v-rect"],
32+
\ "c": ["%9*", "cmdline"],
33+
\ "s": ["%7*", "select"],
34+
\ "S": ["%7*", "s-line"],
35+
\ "\<C-s>": ["%7*", "s-rect"],
36+
\ "t": ["%9*", "term"],
37+
\})
38+
39+
40+
function! MellowStatusline(is_active) abort
41+
let l:statusline = ''
42+
43+
" Construct format string, using %(...%) to hide optional blocks.
44+
if a:is_active
45+
" Mode indicator, colors are dynamic so DON'T USE A %{} BLOCK.
46+
let l:statusline .= mellow_statusline#Mode(g:mellow_mode_map)
47+
" Short file path.
48+
let l:statusline .= '%( %1*%{mellow_statusline#File()}%<%*%)'
49+
" Special file flags.
50+
let l:statusline .= '%( %3*%{mellow_statusline#Flags()}%*%)'
51+
" Git branch indicator.
52+
let l:statusline .= '%( %4*%{mellow_statusline#GitBranch()}%*%)'
53+
" Switch to left side.
54+
let l:statusline .= '%='
55+
" Line and column numbers.
56+
let l:statusline .= '%1*%l,%c%V%*'
57+
" ALE linter status.
58+
let l:statusline .= '%( %3*%{mellow_statusline#ALE()}%*%)'
59+
" Indentation warnings.
60+
let l:statusline .= '%( %3*%{mellow_statusline#CheckIndent()}%*%)'
61+
" File type (TODO: add input indicator).
62+
let l:statusline .= '%( %1*%{&ft}%*%)'
63+
" Add trailing space (balances leading space before mode indicator).
64+
let l:statusline .= ' '
65+
else
66+
" Inactive statusline: subset of the above, without %User* colors.
67+
let l:statusline .= '%( %{mellow_statusline#File()}%<%)'
68+
let l:statusline .= '%( %{mellow_statusline#Flags()}%)'
69+
let l:statusline .= '%='
70+
let l:statusline .= '%l,%c%V'
71+
let l:statusline .= ' '
72+
endif
73+
74+
return l:statusline
75+
endfunction
76+
77+
78+
function! s:UpdateInactiveStatuslines() abort
79+
" From https://github.com/bluz71/vim-moonfly-statusline
80+
" Iterate over windows and set inactive statuslines, required at startup.
81+
for winnum in range(1, winnr('$'))
82+
if winnum != winnr()
83+
call setwinvar(winnum, '&statusline', '%!MellowStatusline(v:false)')
84+
endif
85+
endfor
86+
endfunction
87+
88+
89+
augroup mellow_statusline
90+
" Autocommands for setting the statusline.
91+
autocmd!
92+
autocmd CursorHold,BufWritePost * unlet! b:mellow_indent_warning
93+
autocmd VimEnter * call s:UpdateInactiveStatuslines()
94+
autocmd WinEnter,BufWinEnter * setlocal statusline=%!MellowStatusline(v:true)
95+
autocmd WinLeave * setlocal statusline=%!MellowStatusline(v:false)
96+
augroup END

0 commit comments

Comments
 (0)