]> Sergey Matveev's repositories - nnn.git/commitdiff
Support toggle exe
authorArun Prakash Jana <engineerarun@gmail.com>
Thu, 2 Jan 2020 17:43:56 +0000 (23:13 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Thu, 2 Jan 2020 18:06:08 +0000 (23:36 +0530)
README.md
plugins/README.md
plugins/autojump
plugins/chmodx [deleted file]
src/nnn.c
src/nnn.h

index 17d48fda550f3ff704594606bf3836d844f130e2..cb0468ba89eeeafcc4e868aadc03f2e95e0631a6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ Visit the [Wiki](https://github.com/jarun/nnn/wiki) for concepts, program usage,
   - Notification on cp, mv, rm completion
   - Copy file paths to system clipboard on select
   - Create (with parents), rename, duplicate (anywhere) files and dirs
-  - Launch GUI apps, run commands, spawn a shell
+  - Launch GUI apps, run commands, spawn a shell, toggle executable
   - Hovered file set as `$nnn` at prompt and spawned shell
   - Lock terminal (needs a locker)
 - Privacy-aware (no unconfirmed user data collection)
index 25c5b57e22ad97e118bdfc785f5ce2c62f716374..ecc0478997faa614fb76c53b08c2ac096373125f 100644 (file)
@@ -18,7 +18,6 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
 | boom | Play random music from dir | sh | [moc](http://moc.daper.net/) |
 | dups | List non-empty duplicate files in current dir | sh | find, md5sum,<br>sort uniq xargs |
 | chksum | Create and verify checksums | sh | md5sum,<br>sha256sum |
-| chmodx | Toggle executable status of hovered file | sh | chmod |
 | diffs | Diff for selection (limited to 2 for directories) | sh | vimdiff |
 | dragdrop | Drag/drop files from/into nnn | sh | [dragon](https://github.com/mwh/dragon) |
 | fzcd | Change to the directory of a fuzzy-selected file/dir | sh | fzf/fzy<br>fd/fdfind/find |
index b30530fe861ff55d81af0bd27da4f47664a61db4..ef39dd91d78bc30851dcd1badc385aeaa3adb8f4 100755 (executable)
@@ -15,5 +15,6 @@ if which autojump >/dev/null 2>&1; then
     odir="$(autojump "$dir")"
     printf "%s" "0$odir" > "$NNN_PIPE"
 else
-    exit 1
+    printf "autojump missing"
+    read -r _
 fi
diff --git a/plugins/chmodx b/plugins/chmodx
deleted file mode 100755 (executable)
index 1ad8467..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env sh
-
-# Description: Toggle executable status of hovered file
-#
-# Shell: POSIX compliant
-# Author: Arun Prakash Jana
-
-if ! [ -z "$1" ]; then
-    if [ -x "$1" ]; then
-        chmod -x "$1"
-    else
-        chmod +x "$1"
-    fi
-fi
index 85d52fe9707cc8cf5126e4dc6b4168866af78b52..afe7fae4a328547142791748e27104d76b6dc78f 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3108,6 +3108,13 @@ static bool show_stats(const char *fpath, const struct stat *sb)
        return TRUE;
 }
 
+static bool xchmod(const char *fpath, mode_t mode)
+{
+       (S_IXUSR & mode) ? (mode &= ~(S_IXUSR | S_IXGRP | S_IXOTH)) : (mode |= (S_IXUSR | S_IXGRP | S_IXOTH));
+
+       return (chmod(fpath, mode) == 0);
+}
+
 static size_t get_fs_info(const char *path, bool type)
 {
        struct statvfs svb;
@@ -3491,7 +3498,7 @@ static void show_help(const char *path)
                  "cV  Move sel here%-10c^V  Copy/move sel as\n"
                  "cX  Delete sel%-13c^X  Delete entry\n"
                  "ce  Edit in EDITOR%-10cp  Open in PAGER\n"
-                 "ci  Archive entry%-0c\n"
+                 "ci  Archive entry%-11c*  Toggle exe\n"
                "1ORDER TOGGLES\n"
                  "cS  Disk usage%-14cA  Apparent du\n"
                  "cz  Size%-20ct  Time\n"
@@ -4849,13 +4856,19 @@ nochange:
                        if (ndents)
                                copycurname();
                        goto begin;
-               case SEL_STATS:
+               case SEL_STATS: // fallthrough
+               case SEL_CHMODX:
                        if (ndents) {
                                mkpath(path, dents[cur].name, newpath);
-                               if (lstat(newpath, &sb) == -1 || !show_stats(newpath, &sb)) {
+                               if (lstat(newpath, &sb) == -1
+                                   || (sel == SEL_STATS && !show_stats(newpath, &sb))
+                                   || (sel == SEL_CHMODX && !xchmod(newpath, sb.st_mode))) {
                                        printwarn(&presel);
                                        goto nochange;
                                }
+
+                               if (sel == SEL_CHMODX)
+                                       dents[cur].mode ^= S_IXUSR;
                        }
                        break;
                case SEL_REDRAW: // fallthrough
index 4ef40bf232db213a2b7dfc19a6131117b929c405..4e1311cf78d360a87f58977921238ae1f9b5c03f 100644 (file)
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -65,6 +65,7 @@ enum action {
        SEL_TOGGLEDOT,
        SEL_DETAIL,
        SEL_STATS,
+       SEL_CHMODX,
        SEL_ARCHIVE,
        SEL_FSIZE,  /* file size */
        SEL_ASIZE,  /* apparent size */
@@ -177,6 +178,8 @@ static struct key bindings[] = {
        { 'd',            SEL_DETAIL },
        /* File details */
        { 'D',            SEL_STATS },
+       /* Toggle executable status */
+       { '*',            SEL_CHMODX },
        /* Create archive */
        { 'i',            SEL_ARCHIVE },
        /* Toggle sort by size */