From ae051d2bf3841213dcfc2b8a7d942157a1bb7def Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Mon, 11 Jul 2022 15:15:56 +0200 Subject: [PATCH 1/5] Fix checkpatches duplicate make --- patches/check-patches.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/patches/check-patches.sh b/patches/check-patches.sh index 254af9fc6..43459ed4e 100755 --- a/patches/check-patches.sh +++ b/patches/check-patches.sh @@ -17,7 +17,6 @@ for ((n=1; n < z; ++n)); do printf "%s=%d " "${patches[$i]}" "$(( (n & (1 << i)) != 0 ))" done | tee "/dev/stderr" | ( make clean -s - xargs make 2>&1 if ! xargs make 2>&1; then echo "[FAILED]" >&2 kill -SIGUSR1 "$pid" From fdb3c64bc2f016fcefbb655723e26908f3176f01 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Wed, 13 Jul 2022 21:20:05 +0530 Subject: [PATCH 2/5] Fix double order chars on filter case match change --- src/nnn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nnn.c b/src/nnn.c index 9844935e5..9eb91396f 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -3152,7 +3152,7 @@ static void showfilterinfo(void) if (cfg.fileinfo && ndents && get_output("file", "-b", pdents[cur].name, -1, FALSE, FALSE)) mvaddstr(xlines - 2, 2, g_buf); else { - snprintf(info + i, REGEX_MAX - i - 1, " %s [/], %s [:]", + snprintf(info + i, REGEX_MAX - i - 1, " %s [/], %4s [:]", (cfg.regex ? "reg" : "str"), ((fnstrstr == &strcasestr) ? "ic" : "noic")); } From 7fde7653d533722fb810dd49252afe99533d709b Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Thu, 14 Jul 2022 08:08:31 +0530 Subject: [PATCH 3/5] Show volume used information in help --- src/nnn.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/nnn.c b/src/nnn.c index 9eb91396f..5344ebfaf 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -262,8 +262,9 @@ #define VLEN 3 /* Volume info */ -#define FREE 0 -#define CAPACITY 1 +#define VFS_AVAIL 0 +#define VFS_USED 1 +#define VFS_SIZE 2 /* TYPE DEFINITIONS */ typedef unsigned int uint_t; @@ -4527,17 +4528,20 @@ static bool xchmod(const char *fpath, mode_t mode) return (chmod(fpath, mode) == 0); } -static size_t get_fs_info(const char *path, bool type) +static size_t get_fs_info(const char *path, uchar_t type) { struct statvfs svb; if (statvfs(path, &svb) == -1) return 0; - if (type == CAPACITY) - return (size_t)svb.f_blocks << ffs((int)(svb.f_frsize >> 1)); + if (type == VFS_AVAIL) + return (size_t)svb.f_bavail << ffs((int)(svb.f_frsize >> 1)); - return (size_t)svb.f_bavail << ffs((int)(svb.f_frsize >> 1)); + if (type == VFS_USED) + return ((size_t)svb.f_blocks - (size_t)svb.f_bfree) << ffs((int)(svb.f_frsize >> 1)); + + return (size_t)svb.f_blocks << ffs((int)(svb.f_frsize >> 1)); /* VFS_SIZE */ } /* Create non-existent parents and a file or dir */ @@ -5069,13 +5073,14 @@ static void show_help(const char *path) ++end; } - dprintf(fd, "\nLOCATIONS:\n"); + dprintf(fd, "\nLOCATIONS\n"); for (uchar_t i = 0; i < CTX_MAX; ++i) if (g_ctx[i].c_cfg.ctxactive) dprintf(fd, " %u: %s\n", i + 1, g_ctx[i].c_path); - dprintf(fd, "\nVOLUME: %s of ", coolsize(get_fs_info(path, FREE))); - dprintf(fd, "%s free\n\n", coolsize(get_fs_info(path, CAPACITY))); + dprintf(fd, "\nVOLUME: avail:%s ", coolsize(get_fs_info(path, VFS_AVAIL))); + dprintf(fd, "used:%s ", coolsize(get_fs_info(path, VFS_USED))); + dprintf(fd, "size:%s\n\n", coolsize(get_fs_info(path, VFS_SIZE))); if (bookmark) { dprintf(fd, "BOOKMARKS\n"); @@ -6296,8 +6301,8 @@ static void statusbar(char *path) xstrsncpy(buf, coolsize(dir_blocks << blk_shift), 12); - printw("%cu:%s free:%s files:%llu %lluB %s\n", - (cfg.apparentsz ? 'a' : 'd'), buf, coolsize(get_fs_info(path, FREE)), + printw("%cu:%s avail:%s files:%llu %lluB %s\n", + (cfg.apparentsz ? 'a' : 'd'), buf, coolsize(get_fs_info(path, VFS_AVAIL)), num_files, (ullong_t)pent->blocks << blk_shift, ptr); } else { /* light or detail mode */ char sort[] = "\0\0\0\0\0"; From 19bd0fd4521f0f9ef09417efdd719f59a11dc5e1 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 16 Jul 2022 22:44:53 +0530 Subject: [PATCH 4/5] Minor improvements --- misc/CONTRIBUTING.md | 2 ++ src/nnn.c | 9 ++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/misc/CONTRIBUTING.md b/misc/CONTRIBUTING.md index cd305a93b..4fd61cd47 100644 --- a/misc/CONTRIBUTING.md +++ b/misc/CONTRIBUTING.md @@ -7,6 +7,8 @@ Before suggesting changes, please read a bit about [the design principles nnn fo `nnn` follows the Linux kernel coding style closely. The C source code uses TABs and the plugins use 4 spaces for indentation. +Changes should not break the patch framework. Please run `make checkpatches` before raising a PR. + CI runs `shellcheck` on plugins. Please watch out for any failures if you are modifying/adding a plugin. ## Resources diff --git a/src/nnn.c b/src/nnn.c index 5344ebfaf..18e4c601d 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -1113,11 +1113,7 @@ static size_t mkpath(const char *dir, const char *name, char *out) if (name[0] != '/') { // NOLINT /* Handle root case */ - if (istopdir(dir)) - len = 1; - else - len = xstrsncpy(out, dir, PATH_MAX); - + len = istopdir(dir) ? 1 : xstrsncpy(out, dir, PATH_MAX); out[len - 1] = '/'; // NOLINT } return (xstrsncpy(out + len, name, PATH_MAX - len) + len); @@ -2440,8 +2436,7 @@ static bool plugscript(const char *plugin, uchar_t flags) static void opstr(char *buf, char *op) { - snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c '%s \"$0\" \"$@\" . < /dev/tty' < %s", - op, selpath); + snprintf(buf, CMD_LEN_MAX, "xargs -0 sh -c '%s \"$0\" \"$@\" . < /dev/tty' < %s", op, selpath); } static bool rmmulstr(char *buf) From 4dcd563ab106e9c9898d02e0771f4df4567691b2 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 16 Jul 2022 23:17:32 +0530 Subject: [PATCH 5/5] Add Makefile target shellcheck --- .circleci/config.yml | 2 +- Makefile | 3 +++ misc/CONTRIBUTING.md | 5 +++-- plugins/boom | 2 +- plugins/cdpath | 1 + plugins/fzcd | 3 ++- plugins/fzopen | 1 + plugins/gutenread | 4 ++-- plugins/imgur | 2 ++ plugins/mimelist | 1 + 10 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cc9b83a69..51bc78810 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -75,7 +75,7 @@ jobs: echo "########## clang-tidy-11 ##########" clang-tidy-11 src/* -- -I/usr/include -I/usr/include/ncursesw echo "########## shellcheck ##########" - find plugins/ -type f -not -name "*.md" -exec shellcheck -e SC1090,SC2230 {} + + find plugins/ -type f -not -name "*.md" -exec shellcheck {} + package-and-publish: machine: true diff --git a/Makefile b/Makefile index 721d0b67b..3eaa28b78 100644 --- a/Makefile +++ b/Makefile @@ -261,6 +261,9 @@ musl: ./musl-static-ubuntu.sh 1 rm ./musl-static-ubuntu.sh +shellcheck: + find ./plugins/ -type f -not -name "*.md" -exec shellcheck {} + + dist: mkdir -p nnn-$(VERSION) $(CP) -r $(DISTFILES) nnn-$(VERSION) diff --git a/misc/CONTRIBUTING.md b/misc/CONTRIBUTING.md index 4fd61cd47..5b06c5f59 100644 --- a/misc/CONTRIBUTING.md +++ b/misc/CONTRIBUTING.md @@ -7,9 +7,10 @@ Before suggesting changes, please read a bit about [the design principles nnn fo `nnn` follows the Linux kernel coding style closely. The C source code uses TABs and the plugins use 4 spaces for indentation. -Changes should not break the patch framework. Please run `make checkpatches` before raising a PR. +- Code changes should not break the patch framework. Please run `make checkpatches` to ensure. +- Run `make shellcheck` if adding/modifying plugins. -CI runs `shellcheck` on plugins. Please watch out for any failures if you are modifying/adding a plugin. +CI runs patch framework sanity test and `shellcheck`. Please watch out for any failures after raising the PR. ## Resources The [wiki](https://github.com/jarun/nnn/wiki/Developer-guides) has some resources for developers you might be interested in: building, debugging... diff --git a/plugins/boom b/plugins/boom index 77bb1b8c8..aab466fa0 100755 --- a/plugins/boom +++ b/plugins/boom @@ -9,7 +9,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -GUIPLAYER="${GUIPLAYER}" +GUIPLAYER="${GUIPLAYER:-""}" NUMTRACKS="${NUMTRACKS:-100}" if [ -n "$GUIPLAYER" ]; then diff --git a/plugins/cdpath b/plugins/cdpath index 4ef0da23e..663cb26a2 100755 --- a/plugins/cdpath +++ b/plugins/cdpath @@ -16,6 +16,7 @@ # Shell: POSIX compliant # Author: Yuri Kloubakov +# shellcheck disable=SC1090,SC1091 . "$(dirname "$0")"/.nnn-plugin-helper # Get a list of (symbolic links to) directories for every element of CDPATH diff --git a/plugins/fzcd b/plugins/fzcd index 28bd67e78..125092cbf 100755 --- a/plugins/fzcd +++ b/plugins/fzcd @@ -22,10 +22,11 @@ IFS="$(printf '\n\r')" +# shellcheck disable=SC1090,SC1091 . "$(dirname "$0")"/.nnn-plugin-helper CTX=+ -LIST="$LIST" +LIST="${LIST:-""}" if ! type fzf >/dev/null 2>&1; then printf "fzf missing" diff --git a/plugins/fzopen b/plugins/fzopen index 57035b5ca..17b058563 100755 --- a/plugins/fzopen +++ b/plugins/fzopen @@ -20,6 +20,7 @@ NUKE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/nuke" USE_NUKE=0 +# shellcheck disable=SC1090,SC1091 . "$(dirname "$0")"/.nnn-plugin-helper if type fzf >/dev/null 2>&1; then diff --git a/plugins/gutenread b/plugins/gutenread index ba41facd8..036ff3514 100755 --- a/plugins/gutenread +++ b/plugins/gutenread @@ -18,11 +18,11 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana -EBOOK_ID="${EBOOK_ID}" +EBOOK_ID="${EBOOK_ID:-""}" DIR="${XDG_CACHE_HOME:-$HOME/.cache}/nnn/gutenbooks/$EBOOK_ID" BROWSE_LINK="https://www.gutenberg.org/ebooks/search/?sort_order=downloads" BROWSER="${BROWSER:-w3m}" -READER="${READER}" +READER="${READER:-""}" if [ -n "$EBOOK_ID" ]; then if [ ! -e "$DIR" ]; then diff --git a/plugins/imgur b/plugins/imgur index 373de0551..16d21bcd0 100755 --- a/plugins/imgur +++ b/plugins/imgur @@ -112,6 +112,7 @@ check_update="true" settings_path="${HOME}/.config/imgur-screenshot/settings.conf" if [ -f "${settings_path}" ]; then + # shellcheck disable=SC1090 source "${settings_path}" fi @@ -204,6 +205,7 @@ function load_access_token() { token_expire_time=0 # check for saved access_token and its expiration date if [ -f "${credentials_file}" ]; then + # shellcheck disable=SC1090 source "${credentials_file}" fi current_time="$(date +%s)" diff --git a/plugins/mimelist b/plugins/mimelist index 586cc7cd1..ccfe05a96 100755 --- a/plugins/mimelist +++ b/plugins/mimelist @@ -5,6 +5,7 @@ # Shell: POSIX compliant # Author: Arun Prakash Jana +# shellcheck disable=SC1090,SC1091 . "$(dirname "$0")"/.nnn-plugin-helper printf "mime (e.g., video/audio/image): "