]> Sergey Matveev's repositories - nnn.git/commitdiff
introduce new plugin for jumping git root
authorPatrick <patrickf3139@gmail.com>
Fri, 24 Dec 2021 01:44:27 +0000 (17:44 -0800)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 25 Dec 2021 02:43:43 +0000 (08:13 +0530)
plugins/README.md
plugins/gitroot [new file with mode: 0755]

index 40427b3fd82797420246a66ce4a5cddbe94b532c..88449c376aff0eb674446fa896ee10519fa69513 100644 (file)
@@ -29,7 +29,8 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
 | [fzopen](fzopen) | Fuzzy find file(s) in subtree to edit/open/pick | sh | fzf, xdg-open/open |
 | [fzplug](fzplug) | Fuzzy find, preview and run other plugins | sh | fzf |
 | [getplugs](getplugs) | Update plugins to installed `nnn` version | sh | curl |
-| [gpg\*](gpg\*) | Encrypt/decrypt files using GPG [✓] | sh | gpg |
+| [gitroot](gitroot) | Cd to the root of current git repo | sh | git |
+| [gpge](gpge) | Encrypt/decrypt files using GPG [✓] | sh | gpg |
 | [gutenread](gutenread) | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m<br>[epr](https://github.com/wustho/epr) (optional) |
 | [imgresize](imgresize) | Batch resize images in dir to screen resolution | sh | [imgp](https://github.com/jarun/imgp) |
 | [imgur](imgur) | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) | bash | - |
diff --git a/plugins/gitroot b/plugins/gitroot
new file mode 100755 (executable)
index 0000000..4428d1e
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env sh
+
+# Description: cd to the top level of the current git repository in the current context
+# Dependencies: git
+# Shell: sh
+# Author: https://github.com/PatrickF1
+
+root="$(git rev-parse --show-toplevel 2>/dev/null)"
+if [ -n "$root" ]; then
+    printf "%s" "0c$root" > "$NNN_PIPE"
+else
+    printf "Not in a git repository"
+    read -r _
+    exit 1
+fi