Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple os-detection with shell script #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bin/os-detect
Original file line number Diff line number Diff line change
@@ -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;;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these don't exist, we'll need to print a warning to install them!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I was too late to respond to this. based on 000bbf7#r470224199 i think we could print a warning. and then do exit from os-detect file. is it good?

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

36 changes: 22 additions & 14 deletions bin/zkt
Original file line number Diff line number Diff line change
@@ -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";;
Copy link

@bew bew Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put this part in the os-detect file with an exit?
It will not run anyway, and I think it would simplify the zkt{,-raw} scripts

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just got the idea from you, just adding exit $? in the end of os-detect right?to be honest, my knowledge of shell scripts is lacking

*)
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
16 changes: 12 additions & 4 deletions bin/zkt-raw
Original file line number Diff line number Diff line change
@@ -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