├── LICENSE ├── README.md ├── autoload └── ddc_cmdline_history.vim ├── denops └── @ddc-sources │ └── cmdline_history.ts └── doc └── ddc-source-cmdline_history.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT license 2 | 3 | Copyright (c) Shougo Matsushita 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ddc-source-cmdline_history 2 | 3 | Command history completion for ddc.vim 4 | 5 | This source collects items from `histget()`. It is useful for command line 6 | completion. 7 | 8 | ## Required 9 | 10 | ### denops.vim 11 | 12 | https://github.com/vim-denops/denops.vim 13 | 14 | ### ddc.vim 15 | 16 | https://github.com/Shougo/ddc.vim 17 | 18 | ## Configuration 19 | 20 | ```vim 21 | call ddc#custom#patch_global('sources', ['cmdline_history']) 22 | 23 | call ddc#custom#patch_global('sourceOptions', #{ 24 | \ cmdline_history: #{ mark: 'history' }, 25 | \ }) 26 | ``` 27 | -------------------------------------------------------------------------------- /autoload/ddc_cmdline_history.vim: -------------------------------------------------------------------------------- 1 | function! ddc_cmdline_history#get(max) abort 2 | const type = getcmdtype() 3 | const max = [a:max, type->histnr()]->min() 4 | if max < 1 5 | return [] 6 | endif 7 | 8 | let histories = range(1, max)->map({ _, val -> type->histget(-val) }) 9 | 10 | " Filter 11 | const compltype = getcmdcompltype() 12 | if compltype ==# 'dir' 13 | let histories = histories 14 | \ ->filter({ _, val -> val->isdirectory() }) 15 | elseif compltype ==# 'file' 16 | let histories = histories 17 | \ ->filter({ _, val -> val->isdirectory() || val->filereadable() }) 18 | endif 19 | 20 | return histories 21 | endfunction 22 | -------------------------------------------------------------------------------- /denops/@ddc-sources/cmdline_history.ts: -------------------------------------------------------------------------------- 1 | import { 2 | type Context, 3 | type DdcOptions, 4 | type Item, 5 | type SourceOptions, 6 | } from "jsr:@shougo/ddc-vim@~9.1.0/types"; 7 | import { BaseSource } from "jsr:@shougo/ddc-vim@~9.1.0/source"; 8 | 9 | import type { Denops } from "jsr:@denops/core@~7.0.0"; 10 | 11 | type Params = { 12 | maxSize: number; 13 | }; 14 | 15 | export class Source extends BaseSource { 16 | override async gather(args: { 17 | denops: Denops; 18 | context: Context; 19 | options: DdcOptions; 20 | sourceOptions: SourceOptions; 21 | sourceParams: Params; 22 | completeStr: string; 23 | }): Promise { 24 | const maxSize = args.sourceParams.maxSize; 25 | const histories = await args.denops.call( 26 | "ddc_cmdline_history#get", 27 | maxSize, 28 | ) as string[]; 29 | 30 | if (args.context.input.indexOf(" ") < 0) { 31 | return histories.map((word) => ({ word })); 32 | } 33 | 34 | const inputLength = args.context.input.length - args.completeStr.length; 35 | const input = inputLength > 0 36 | ? args.context.input.substring(0, inputLength) 37 | : args.context.input; 38 | return histories.filter( 39 | (word) => 40 | word.startsWith(input) && word.indexOf("\r") < 0 && 41 | word.indexOf("\n") < 0, 42 | ).map((word) => ({ word: word.substring(inputLength) })); 43 | } 44 | 45 | override params(): Params { 46 | return { 47 | maxSize: 1000, 48 | }; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /doc/ddc-source-cmdline_history.txt: -------------------------------------------------------------------------------- 1 | *ddc-source-cmdline_history.txt* cmdline history completion for ddc.vim 2 | 3 | Author: Shougo 4 | License: MIT license 5 | 6 | CONTENTS *ddc-source-cmdline_history-contents* 7 | 8 | Introduction |ddc-source-cmdline_history-introduction| 9 | Install |ddc-source-cmdline_history-install| 10 | Examples |ddc-source-cmdline_history-examples| 11 | 12 | 13 | ============================================================================== 14 | INTRODUCTION *ddc-source-cmdline_history-introduction* 15 | 16 | This source collects command line history from |histget()|. 17 | 18 | 19 | ============================================================================== 20 | INSTALL *ddc-source-cmdline_history-install* 21 | 22 | Please install both "ddc.vim" and "denops.vim". 23 | 24 | https://github.com/Shougo/ddc.vim 25 | https://github.com/vim-denops/denops.vim 26 | 27 | 28 | ============================================================================== 29 | EXAMPLES *ddc-source-cmdline_history-examples* 30 | > 31 | call ddc#custom#patch_global('sources', ['cmdline']) 32 | 33 | call ddc#custom#patch_global(sourceOptions, #{ 34 | \ cmdline_history: #{ mark: 'history' }, 35 | \ }) 36 | < 37 | 38 | ============================================================================== 39 | vim:tw=78:ts=8:ft=help:norl:noet:fen:noet: 40 | --------------------------------------------------------------------------------