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..c92fd89 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[ \ + ${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 && \ + 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