]> Sergey Matveev's repositories - nnn.git/commitdiff
Add plugin bulknew (#662)
authorKlzXS <azszwymmvqdi@yahoo.com>
Sat, 20 Jun 2020 13:39:32 +0000 (13:39 +0000)
committerGitHub <noreply@github.com>
Sat, 20 Jun 2020 13:39:32 +0000 (15:39 +0200)
* Add plugin bulknew

* Update documentation

* Update dependencies

* Add whitespace note

plugins/README.md
plugins/bulknew [new file with mode: 0755]
plugins/preview-tabbed
plugins/preview-tui

index 841c6b8358f6a793c0030c26dbb7ce88163c2f13..2af105e75b3d14a2afd108f03885660d4c541a4f 100644 (file)
@@ -29,13 +29,14 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`.
 | [autojump](autojump) | Navigate to dir/path | sh | autojump |
 | [bookmarks](bookmarks) | Use named bookmarks managed with symlinks | sh | fzf |
 | [boom](boom) | Play random music from dir | sh | [moc](http://moc.daper.net/) |
+| [bulknew](bulknew) | Create multiple files/dirs at once | bash | sed, xargs, mktemp |
 | [dups](dups) | List non-empty duplicate files in current dir | sh | find, md5sum,<br>sort uniq xargs |
 | [chksum](chksum) | Create and verify checksums | sh | md5sum,<br>sha256sum |
-| [diffs](diffs) | Diff for selection (limited to 2 for directories) | sh | vimdiff |
+| [diffs](diffs) | Diff for selection (limited to 2 for directories) | sh | vimdiff, mktemp |
 | [dragdrop](dragdrop) | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) |
 | [finder](finder) | Run custom find command and list | sh | - |
 | [fzcd](fzcd) | Change to the directory of a fuzzy-selected file/dir | sh | fzf |
-| [fzhist](fzhist) | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzf |
+| [fzhist](fzhist) | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzf, mktemp |
 | [fzopen](fzopen) | Fuzzy find a file in dir subtree and edit or open | sh | fzf, xdg-open |
 | [fzz](fzz) | Change to any directory in the z database with fzf | sh | fzf, z |
 | [getplugs](getplugs) | Update plugins to installed `nnn` version | sh | curl |
@@ -54,7 +55,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`.
 | [moclyrics](moclyrics) | Show lyrics of the track playing in moc | sh | [ddgr](https://github.com/jarun/ddgr), [moc](http://moc.daper.net/) |
 | [mocplay](mocplay) | Append (and/or play) selection/dir/file in moc | sh | [moc](http://moc.daper.net/) |
 | [mp3conv](mp3conv) | Extract audio from multimedia as mp3 | sh | ffmpeg |
-| [nbak](nbak) | Backs up `nnn` config | sh | tar, awk |
+| [nbak](nbak) | Backs up `nnn` config | sh | tar, awk, mktemp |
 | [nmount](nmount) | Toggle mount status of a device as normal user | sh | pmount, udisks2 |
 | [nuke](nuke) | Sample file opener (CLI-only by default) | sh | _see in-file docs_ |
 | [oldbigfile](oldbigfile) | List large files by access time | sh | find, sort |
diff --git a/plugins/bulknew b/plugins/bulknew
new file mode 100755 (executable)
index 0000000..4010662
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/env sh
+
+# Description: Allows for creation of multiple files/directories at the same time.
+#              Plugin opens a temp file where each entry is to be written on a separate line
+#
+# Note: Only relative paths are supported. Absolute paths are ignored
+#       Leading and trailing whitespace in path names is also ignored
+#
+# Shell: POSIX compliant
+# Author: KlzXS
+
+EDITOR="${EDITOR:-vi}"
+TMPDIR="${TMPDIR:-/tmp}"
+
+printf "'f'ile / 'd'ir? "
+read -r resp
+
+if [ "$resp" = "f" ]; then
+       #shellcheck disable=SC2016
+       cmd='mkdir -p "$(dirname "{}")" && touch "{}"'
+elif [ "$resp" = "d" ]; then
+       cmd='mkdir -p {}'
+else
+       exit 1
+fi
+
+tmpfile=$(mktemp "$TMPDIR/.nnnXXXXXX")
+$EDITOR "$tmpfile"
+
+sed "/^\//d" "$tmpfile" | xargs -n1 -I{} sh -c "$cmd"
+
+rm "$tmpfile"
index 4998de6b345dfad7f28fe857410ce56c01586a14..9fefee144448ac194657493344257928fb57d159 100755 (executable)
@@ -15,6 +15,7 @@
 #    dependencies, see the script itself
 #  - vim (or any editor/pager really)
 #  - file
+#  - mktemp
 #  - xdotool (optional, to keep main window focused)
 #
 # How to use:
index fafee764660bfcaaf358141eb05c788349729865..f12bf1e9ad22faaba5996171a837b3d4e8a945d7 100755 (executable)
@@ -12,6 +12,7 @@
 #    - less or $PAGER
 #    - tree or exa or ls
 #    - mediainfo or file
+#    - mktemp
 #    - unzip
 #    - tar
 #    - man