├── LICENSE ├── README.md ├── autoload └── fern │ └── scheme │ └── file │ └── mapping │ └── git.vim └── plugin └── fern_mapping_git.vim /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Alisue, hashnote.net 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fern-mapping-git.vim 2 | 3 | [![fern plugin](https://img.shields.io/badge/🌿%20fern-plugin-yellowgreen)](https://github.com/lambdalisue/fern.vim) 4 | 5 | [fern.vim](https://github.com/lambdalisue/fern.vim) plugin which add Git related mappings on `file://` scheme. 6 | 7 | **UNDER DEVELOPMENT** 8 | 9 | ## Usage 10 | 11 | This plugin automatically add the following actions to `file` scheme. 12 | 13 | | Mapping | Action | Description | 14 | | ------- | ------------- | ----------------------------------- | 15 | | `<<` | `git-stage` | Stage the selected/cursor node(s) | 16 | | `>>` | `git-unstage` | Unstage the selected/cursor node(s) | 17 | 18 | ## See also 19 | 20 | - [fern-git-status](https://github.com/lambdalisue/fern-git-status.vim) - Add Git status badge 21 | -------------------------------------------------------------------------------- /autoload/fern/scheme/file/mapping/git.vim: -------------------------------------------------------------------------------- 1 | let s:Process = vital#fern#import('Async.Promise.Process') 2 | 3 | function! fern#scheme#file#mapping#git#init(disable_default_mappings) abort 4 | nnoremap (fern-action-git-stage) :call call('stage') 5 | nnoremap (fern-action-git-unstage) :call call('unstage') 6 | 7 | if !a:disable_default_mappings 8 | \ && !g:fern#scheme#file#mapping#git#disable_default_mappings 9 | nmap << (fern-action-git-stage) 10 | nmap >> (fern-action-git-unstage) 11 | endif 12 | endfunction 13 | 14 | function! s:call(name, ...) abort 15 | return call( 16 | \ 'fern#mapping#call', 17 | \ [funcref(printf('s:map_%s', a:name))] + a:000, 18 | \) 19 | endfunction 20 | 21 | function! s:map_stage(helper) abort 22 | if a:helper.sync.get_scheme() !=# 'file' 23 | throw printf("git-stage action requires 'file' scheme") 24 | endif 25 | let root = a:helper.sync.get_root_node() 26 | let nodes = a:helper.sync.get_selected_nodes() 27 | let nodes = empty(nodes) ? [a:helper.sync.get_cursor_node()] : nodes 28 | let paths = map(copy(nodes), { -> v:val._path }) 29 | 30 | call s:Process.start(['git', '-C', root._path, 'add', '--ignore-errors', '--'] + paths) 31 | \.then({ -> a:helper.async.update_marks([]) }) 32 | \.then({ -> a:helper.async.redraw() }) 33 | endfunction 34 | 35 | function! s:map_unstage(helper) abort 36 | if a:helper.sync.get_scheme() !=# 'file' 37 | throw printf("git-unstage action requires 'file' scheme") 38 | endif 39 | let root = a:helper.sync.get_root_node() 40 | let nodes = a:helper.sync.get_selected_nodes() 41 | let nodes = empty(nodes) ? [a:helper.sync.get_cursor_node()] : nodes 42 | let paths = map(copy(nodes), { -> v:val._path }) 43 | 44 | call s:Process.start(['git', '-C', root._path, 'reset', '--quiet', '--'] + paths) 45 | \.then({ -> a:helper.async.update_marks([]) }) 46 | \.then({ -> a:helper.async.redraw() }) 47 | endfunction 48 | 49 | 50 | let g:fern#scheme#file#mapping#git#disable_default_mappings = get(g:, 'fern#scheme#file#mapping#git#disable_default_mappings', 0) 51 | -------------------------------------------------------------------------------- /plugin/fern_mapping_git.vim: -------------------------------------------------------------------------------- 1 | if exists('g:fern_mapping_git_loaded') 2 | finish 3 | endif 4 | let g:fern_mapping_git_loaded = 1 5 | 6 | call add(g:fern#scheme#file#mapping#mappings, 'git') 7 | --------------------------------------------------------------------------------