From 000bbf7fa13ac480a6fa06faa1a30a52068ec3de Mon Sep 17 00:00:00 2001 From: Arian Anggada Oemar Date: Fri, 17 Jul 2020 12:58:16 +0700 Subject: [PATCH 1/2] simple os-detection with shell script --- bin/os-detect | 13 +++++++++++++ bin/zkt | 36 ++++++++++++++++++++++-------------- bin/zkt-raw | 16 ++++++++++++---- 3 files changed, 47 insertions(+), 18 deletions(-) create mode 100755 bin/os-detect diff --git a/bin/os-detect b/bin/os-detect new file mode 100755 index 0000000..9e86cca --- /dev/null +++ b/bin/os-detect @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# detect os platform +OS_TYPE="$(uname -s)" +case "${OS_TYPE}" in + Linux*) sort_command=sort grep_command=grep;; + Darwin*) sort_command=gsort grep_command=ggrep;; + CYGWIN*) sort_command=sort grep_command=grep;; + OpenBSD*) sort_command=sort grep_command=grep;; + FreeBSD*) sort_command=sort grep_command=grep;; + *) sort_command="UNKNOWN" grep_command="UNKNOWN";; +esac + diff --git a/bin/zkt b/bin/zkt index ac9e821..1b75dad 100755 --- a/bin/zkt +++ b/bin/zkt @@ -1,15 +1,23 @@ #!/bin/bash -zkt-raw | fzf --height 100% --no-info --no-multi \ - --bind "ctrl-o:execute-silent[tmux send-keys -t \{left\} Escape :read Space ! Space echo Space && \ - tmux send-keys -t \{left\} -l '\"\\'{2}'\"' && \ - tmux send-keys -t \{left\} Enter]" \ - --bind "ctrl-y:execute-silent(echo {2} | pbcopy),enter:execute[ \ - ggrep -F --color=always -i {2} *.md -l | \ - fzf --ansi --height 100% --preview-window=top:65% \ - --bind 'enter:execute-silent$ \ - tmux send-keys -t \{left\} Escape :e Space && \ - tmux send-keys -t \{left\} -l \{} && \ - tmux send-keys -t \{left\} Enter \ - $' \ - --preview 'bat --color always --language md --style plain \{}' \ - ]" + +# load os detect script +. os-detect + +case "${grep_command}" in + UNKNOWN*) echo "support only unix system";; + *) + zkt-raw | fzf --height 100% --no-info --no-multi \ + --bind "ctrl-o:execute-silent[tmux send-keys -t \{left\} Escape :read Space ! Space echo Space && \ + tmux send-keys -t \{left\} -l '\"\\'{2}'\"' && \ + tmux send-keys -t \{left\} Enter]" \ + --bind "ctrl-y:execute-silent(echo {2} | pbcopy),enter:execute[ \ + ggrep -F --color=always -i {2} *.md -l | \ + fzf --ansi --height 100% --preview-window=top:65% \ + --bind 'enter:execute-silent$ \ + tmux send-keys -t \{left\} Escape :e Space && \ + tmux send-keys -t \{left\} -l \{} && \ + tmux send-keys -t \{left\} Enter \ + $' \ + --preview 'bat --color always --language md --style plain \{}' \ + ]";; +esac diff --git a/bin/zkt-raw b/bin/zkt-raw index d675c8a..19e018d 100755 --- a/bin/zkt-raw +++ b/bin/zkt-raw @@ -1,6 +1,14 @@ #!/bin/bash # useful for editors, used in zkt -rg -o "#[\w\-_]{3,}" -t md -N --no-filename "$ZK_PATH" | - rg -v "^#(notes-|import-)" | \ - awk ' { tot[$0]++ } END { for (i in tot) print tot[i], "\t", i } ' | \ - gsort -r --numeric-sort + +# load os detect script +. os-detect + +case "${sort_command}" in + UNKNOWN*) echo "support only unix system";; + *) + rg -o "#[\w\-_]{3,}" -t md -N --no-filename "$ZK_PATH" | + rg -v "^#(notes-|import-)" | \ + awk ' { tot[$0]++ } END { for (i in tot) print tot[i], "\t", i } ' | \ + ${sort_command} -r --numeric-sort;; +esac From 1fac76f3f7df7f8cefc39dd471c927e26d2269e4 Mon Sep 17 00:00:00 2001 From: arianao19 Date: Fri, 17 Jul 2020 13:13:21 +0700 Subject: [PATCH 2/2] i forgot to change on zkt script --- bin/zkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/zkt b/bin/zkt index 1b75dad..c92fd89 100755 --- a/bin/zkt +++ b/bin/zkt @@ -11,7 +11,7 @@ case "${grep_command}" in tmux send-keys -t \{left\} -l '\"\\'{2}'\"' && \ tmux send-keys -t \{left\} Enter]" \ --bind "ctrl-y:execute-silent(echo {2} | pbcopy),enter:execute[ \ - ggrep -F --color=always -i {2} *.md -l | \ + ${grep_command} -F --color=always -i {2} *.md -l | \ fzf --ansi --height 100% --preview-window=top:65% \ --bind 'enter:execute-silent$ \ tmux send-keys -t \{left\} Escape :e Space && \