about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRory Bradford <roryrjb@gmail.com>2020-10-10 10:22:39 +0100
committerRory Bradford <roryrjb@gmail.com>2020-10-10 10:22:39 +0100
commita40bd8adb20715582813fb8399dd37e4efee9b37 (patch)
treeb24cb66671e5540f1ab28fc5497c3eb0bf0cada7
parent1c5aba7f1b2a53cdcaf896df118f3c7b42c0251c (diff)
downloadrf-a40bd8adb20715582813fb8399dd37e4efee9b37.tar.gz
Improve Vim integration
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
-rw-r--r--.gitignore2
-rw-r--r--Makefile13
-rw-r--r--README.md19
-rw-r--r--contrib/vim/README.md (renamed from contrib/vim/README)47
-rw-r--r--contrib/vim/plugin/rf.vim16
-rw-r--r--rf.147
-rw-r--r--rf.1.scd42
-rw-r--r--rfconfig.541
-rw-r--r--rfconfig.5.scd43
-rw-r--r--rfignore.520
-rw-r--r--rfignore.5.scd25
11 files changed, 182 insertions, 133 deletions
diff --git a/.gitignore b/.gitignore
index 529ad04..9651efe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 /rf
 *.o
+*.1
+*.5
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 42b5b79..58b045d 100644
--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,16 @@ all: $(BIN)
 $(BIN): $(OBJS)
 	$(CC) $(CFLAGS) -o $(BIN) $(OBJS)
 
-install: $(BIN)
+rf.1: rf.1.scd
+	scdoc < $< > $@
+
+rfignore.5: rfignore.5.scd
+	scdoc < $< > $@
+
+rfconfig.5: rfconfig.5.scd
+	scdoc < $< > $@
+
+install: $(BIN) rf.1 rfignore.5 rfconfig.5
 	mkdir -p \
 		$(DESTDIR)$(PREFIX)/bin \
 		$(DESTDIR)$(PREFIX)/man/man1 \
@@ -28,4 +37,4 @@ install: $(BIN)
 	install -m444 rfconfig.5 $(DESTDIR)$(PREFIX)/man/man5/
 
 clean:
-	rm -vf $(BIN) *.o
+	rm -vf $(BIN) *.o *.1 *.5
diff --git a/README.md b/README.md
index ffdd2d2..450e6b7 100644
--- a/README.md
+++ b/README.md
@@ -2,16 +2,17 @@
 
 > A tiny and simple cross-platform file finder
 
-### Installation
+## Installation
 
-The only requirements are a libc and a C compiler. `rf` has been successfully
-tested on OpenBSD, FreeBSD and Linux (with glibc and musl), on x86, amd64 and arm
-and with clang and gcc.
+### From Source
 
-```
-$ make install
-```
+Absolute minimum requirements are a C99 compiler. `rf` has been successfully
+tested on OpenBSD, FreeBSD and Linux (with glibc and musl), on amd64 and arm
+and with clang and gcc. For man pages you will require
+[__scdoc__(1)](https://sr.ht/~sircmpwn/scdoc/).
 
-### Usage
+    $ make install
 
-See `man rf` for more details and examples.
+## Usage
+
+See `man rf` for more details and examples.
\ No newline at end of file
diff --git a/contrib/vim/README b/contrib/vim/README.md
index 5752ed0..f108c89 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README.md
@@ -1,14 +1,31 @@
-This directory provides basic rf integration in Vim.
+# rf-vim
 
-It can be installed from this directory using make:
+> Simple `rf` Vim integration
 
-    make install
+### Installation
 
-The plugin provides two functions:
+__Manual installation:__
+
+If you are using default Vim paths (so not Neovim for example) you can
+just run `make install`. Otherwise you should just be able to modify your
+`runtimepath` and add `~/.vim/after/`.
+
+__Using vim-plug, Vundle, et al:__
+
+```viml
+Plug 'roryrjb/rf', { 'rtp': 'contrib/vim' }  " vim-plug
+Plugin 'roryrjb/rf', { 'rtp': 'contrib/vim' }  " Vundle
+```
 
-*rf*
+Other plugin systems will likely have very similar options. In a nutshell
+the vim plugin provided here isn't in the root of the repo and assumes
+you have `rf` already installed and present in your `$PATH`.
+
+### Usage
+
+The plugin provides two functions:
 
-    :RF
+__RF:__
 
 This function runs a getchar() loop, allowing you to search from the
 root of the current working directory, using only substring patterns,
@@ -17,18 +34,22 @@ exposing more of the functionality that rf provides.
 
 I usually bind the function like so:
 
-    map <c-p> :RF <CR>
+```
+map <c-p> :RF <CR>
+```
 
 The function is very simple and will call rf with your pattern
 *at every key stroke*. Usually this is performant enough, but
 with extremely large directory trees, you may have to wait several
 seconds for results, which isn't great. Aside from any improvements
-to the implementation, just make sure that any .rfignore files,
+to the implementation, just make sure that any `.rfignore` files,
 whether local or global are ignoring everything that can be ignored.
 
-*rf grep*
+__RFGrep:__
 
-    :RFGrep search-pattern filename-pattern
+```
+:RFGrep search-pattern filename-pattern
+```
 
 This function is a wrapper around `grep -r` and rf. It allows you
 to grep recursively over a smaller subset of files. Again the
@@ -36,10 +57,12 @@ implementation is very simple but with very large directory trees
 or with filename patterns that match a lot of files you may
 hit the argument limit for grep.
 
-*Issues*
+### Issues
 
 Aside from the above mentioned limitations and issues, if you
 are using anything other than a "Bourne" shell (bash, ksh, zsh, sh)
 the functions may not work, in that case you may want to explictly:
 
-    set shell=sh
+```
+set shell=sh
+```
diff --git a/contrib/vim/plugin/rf.vim b/contrib/vim/plugin/rf.vim
index cf4649b..4ea281c 100644
--- a/contrib/vim/plugin/rf.vim
+++ b/contrib/vim/plugin/rf.vim
@@ -3,6 +3,7 @@ if exists('loaded_rf')
 endif
 
 let loaded_rf = 1
+let g:rf_prefix = ""
 
 set errorformat+=%f
 
@@ -60,15 +61,26 @@ function! g:RFPrompt()
             echo "RF: " . l:rf_pattern
             redraw
 
-            let results = system('rf -ws -- ' . shellescape(l:rf_pattern))
+            if len(g:rf_prefix)
+                let results = system('rf -l9 -d ' . shellescape(g:rf_prefix) . ' -s -- ' . shellescape(l:rf_pattern))
+            else
+                let results = system('rf -l9 -ws -- ' . shellescape(l:rf_pattern))
+            endif
+
             let results_list = split(results, '\n')
             let l:rf_results = results_list
 
             if len(results_list) > 0
-                cgete results | copen 9
+                if len(results_list) < 9
+                    execute "cgete results | copen " . len(results_list)
+                else
+                    cgete results | copen 9
+                endif
+
                 redraw
             else
                 cexpr []
+                cclose
             endif
         else
             let l:rf_cmd = 0
diff --git a/rf.1 b/rf.1
deleted file mode 100644
index a600e69..0000000
--- a/rf.1
+++ /dev/null
@@ -1,47 +0,0 @@
-.TH rf 1
-
-.SH NAME
-rf \- a tiny and simple file finder
-
-.SH SYNOPSIS
-.SY rf
-.OP \-d directory
-.OP \-c config
-.OP \-lsvw
-.OP pattern ...
-
-.SH DESCRIPTION
-\fBrf\fR will find files or directories based on one or more glob (or optionally
-substring) patterns, while respecting any ignore rules in \fBrfignore\fR files.
-
-.SH OPTIONS
-.TP
-.BI \-d directory
-Search from specified directory, otherwise defaults to current working directory.
-.
-.TP
-.BI \-c config
-Override config file location.
-.
-.TP
-.BI \-l count
-Limit to specified matches count.
-.
-.TP
-.B \-s
-Match using substrings instead of globs.
-.
-.TP
-.B \-v
-Invert matches.
-.
-.TP
-.B \-w
-Match wholename, including path.
-
-.SH SEE ALSO
-.BR rfignore (5),
-.BR rfconfig (5)
-
-.SH COPYRIGHT
-Copyright \(co 2019, 2020 Rory Bradford <roryrjb@gmail.com>.
diff --git a/rf.1.scd b/rf.1.scd
new file mode 100644
index 0000000..0fb3c3c
--- /dev/null
+++ b/rf.1.scd
@@ -0,0 +1,42 @@
+rf(1)
+
+# NAME
+
+rf - a tiny and simple file finder
+
+# SYNOPSIS
+
+*rf* [*-d* _directory_] [*-c* _config_] [*-lsvw*] [*pattern* _..._]
+
+# DESCRIPTION
+
+*rf* will find files or directories based on one or more glob (or optionally
+substring) patterns, while respecting any ignore rules in *rfignore* files.
+
+# OPTIONS
+
+*-d* directory
+	Search from specified directory, otherwise defaults to current working directory.
+
+*-c* config
+	Override config file location.
+
+*-l* count
+	Limit to specified matches count.
+
+*-s*
+	Match using substrings instead of globs.
+
+*-v*
+	Invert matches.
+
+*-w*
+	Match wholename, including path.
+
+# SEE ALSO
+
+*rfignore*(5), *rfconfig*(5)
+
+# COPYRIGHT
+
+Copyright © 2019 - 2021 Rory Bradford <roryrjb@gmail.com>.
diff --git a/rfconfig.5 b/rfconfig.5
deleted file mode 100644
index 8ad7ab0..0000000
--- a/rfconfig.5
+++ /dev/null
@@ -1,41 +0,0 @@
-.TH rfconfig 5
-
-.SH NAME
-rfconfig \- configure rf behaviour
-
-.SH SYNOPSIS
-$XDG_CONFIG_HOME/rf/config
-
-.SH DESCRIPTION
-An \fBrfconfig\fR file is used to override default behaviour and configure options.
-
-.SH FORMAT
-The config file format is very simple. Comments are only available for a whole
-line and start with #. Any lines that begin with a space are ignored.
-Each valid config line consists of a key value pair with the key and value
-separated by an = character and optionally a single space either side. Additional
-spaces will become part of either the key and/or value.
-
-.SH OPTIONS
-.TP
-.B symlinks
-Read symlinks (value: "true" or "false")
-.
-.TP
-.B wholename
-Match whole path (value "true" or "false")
-.
-.TP
-.B limit
-Limit amount of results (value: a positive integer)
-.
-.TP
-.B wildcard
-Define a custom wildcard character, used in place of * (value: a single ascii character)
-.
-.TP
-.B unmatched error
-Exit with non-zero exit code if there were no matches
-
-.SH COPYRIGHT
-Copyright \(co 2019, 2020 Rory Bradford <roryrjb@gmail.com>.
diff --git a/rfconfig.5.scd b/rfconfig.5.scd
new file mode 100644
index 0000000..64d021c
--- /dev/null
+++ b/rfconfig.5.scd
@@ -0,0 +1,43 @@
+rfconfig(5)
+
+# NAME
+
+rfconfig - configure rf behaviour
+
+# SYNOPSIS
+
+$XDG_CONFIG_HOME/rf/config
+
+# DESCRIPTION
+
+An *rfconfig* file is used to override default behaviour and configure options.
+
+# FORMAT
+
+The config file format is very simple. Comments are only available for a whole
+line and start with #. Any lines that begin with a space are ignored.
+Each valid config line consists of a key value pair with the key and value
+separated by an = character and optionally a single space either side.
+Additional spaces will become part of either the key and/or value.
+
+# OPTIONS
+
+*symlinks*
+	Read symlinks (value: "true" or "false")
+
+*wholename*
+	Match whole path (value "true" or "false")
+
+*limit*
+	Limit amount of results (value: a positive integer)
+
+*wildcard*
+	Define a custom wildcard character, used in place of \*
+	(value: a single ascii character)
+
+*unmatched error*
+	Exit with non-zero exit code if there were no matches
+
+# COPYRIGHT
+
+Copyright © 2019 - 2021 Rory Bradford <roryrjb@gmail.com>.
diff --git a/rfignore.5 b/rfignore.5
deleted file mode 100644
index ec2524e..0000000
--- a/rfignore.5
+++ /dev/null
@@ -1,20 +0,0 @@
-.TH rfignore 5
-
-.SH NAME
-rfignore \- ignore specified paths
-
-.SH SYNOPSIS
-$XDG_CONFIG_HOME/rf/ignore, $HOME/.rfignore, .rfignore
-
-.SH DESCRIPTION
-An \fBrfignore\fR file will be used by \fBrf\fR to ignore files and paths
-when iterating through directories. Any matching patterns will not be displayed.
-.sp
-\fBrf\fR will look in all places specified in the synopsis for glob patterns
-on each line and take them all into account.
-
-.SH SEE ALSO
-.BR glob (7)
-
-.SH COPYRIGHT
-Copyright \(co 2019, 2020 Rory Bradford <roryrjb@gmail.com>.
diff --git a/rfignore.5.scd b/rfignore.5.scd
new file mode 100644
index 0000000..bf44440
--- /dev/null
+++ b/rfignore.5.scd
@@ -0,0 +1,25 @@
+rfignore(5)
+
+# NAME
+
+rfignore - ignore specified paths
+
+# SYNOPSIS
+
+$XDG_CONFIG_HOME/rf/ignore, $HOME/.rfignore, .rfignore
+
+# DESCRIPTION
+
+An *rfignore* file will be used by *rf* to ignore files and paths
+when iterating through directories. Any matching patterns will not be displayed.
+
+*rf* will look in all places specified in the synopsis for glob patterns
+on each line and take them all into account.
+
+# SEE ALSO
+
+*glob*(7)
+
+# COPYRIGHT
+
+Copyright © 2019 - 2021 Rory Bradford <roryrjb@gmail.com>.