We need contributors. Please visit the [ToDo list](https://github.com/jarun/nnn/issues/137).
-If you are using custom scripts which you would like to share with others, please raise a PR to add them under [user-scripts](https://github.com/jarun/nnn/tree/master/scripts/user-scripts).
-
*Love smart and efficient utilities? Explore [my repositories](https://github.com/jarun?tab=repositories). Buy me a cup of coffee if they help you.*
<p align="center">
- [get selection manually](#get-selection-manually)
- [cd on quit](#cd-on-quit)
- [(neo)vim plugin](#neovim-plugin)
+ - [file picker](#file-picker)
- [run custom scripts](#run-custom-scripts)
- [sample scripts](#sample-scripts)
- [launch applications](#launch-applications)
ncp > out.txt
-To use `nnn` as a file picker and redirect the output to other programs, please see [issue #183](https://github.com/jarun/nnn/issues/183).
-
#### cd on quit
To quit `nnn` and switch to the directory last opened follow the instructions below.
`nnn` can be used as a file picker/chooser within vim or neovim. Find the plugin [here](https://github.com/mcchrish/nnn.vim).
+#### file picker
+
+To use `nnn` as a file picker and redirect the output to other programs, use [picker.sh](https://github.com/jarun/nnn/blob/master/scripts/user-scripts/picker.sh).
+
#### run custom scripts
`nnn` can invoke custom scripts with the currently selected file name as argument 1.
##### sample scripts
-- Open image files in current dir in **sxiv**:
-
- #!/usr/bin/env sh
-
- sxiv -q * >/dev/null 2>&1
-
-- Fuzzy find files in **fzy** and open with xdg-open:
-
- #!/usr/bin/env sh
-
- xdg-open $(find -type f | fzy) >/dev/null 2>&1
+Sample scripts for use cases like sxiv or fzy integration are under [user-scripts](https://github.com/jarun/nnn/tree/master/scripts/user-scripts). Feel free to contribute yours!
#### launch applications
--- /dev/null
+#!/bin/bash
+
+# Description: Pick files and pipe the line-separated list to another utility
+#
+# Shell: bash
+# Author: Arun Prakash Jana
+#
+# Usage:
+# Copy this file in your $PATH, make it executable and preferably name it to picker.
+# Run commands like:
+# ls -l `picker`
+# cd `picker`
+# or, in fish shell:
+# ls -l (picker)
+# cd (picker)
+#
+# NOTE: This use case is limited to picking files, other functionality may not work as expected.
+
+nnn -p /tmp/pickerout
+> /tmp/picked
+while read -d $'\0' line ; do
+ echo $line >> /tmp/picked
+done < /tmp/pickerout
+echo $line >> /tmp/picked
+cat /tmp/picked
+
+rm /tmp/pickerout /tmp/picked
/* Initialize curses mode */
static bool initcurses(void)
{
- if (initscr() == NULL) {
+ if (cfg.picker) {
+ if (!newterm(NULL, stderr, stdin)) {
+ fprintf(stderr, "newterm!\n");
+ return FALSE;
+ }
+ } else if (!initscr()) {
char *term = getenv("TERM");
if (term != NULL)
fprintf(stderr, "error opening TERM: %s\n", term);
else
- fprintf(stderr, "initscr() failed\n");
+ fprintf(stderr, "initscr!\n");
return FALSE;
}
}
/* Confirm we are in a terminal */
- if (!isatty(0) || !isatty(1)) {
- fprintf(stderr, "stdin or stdout is not a tty\n");
+ if (!cfg.picker && !(isatty(0) && isatty(1))) {
+ fprintf(stderr, "stdin/stdout !tty\n");
return 1;
}