summaryrefslogtreecommitdiff
path: root/sh/o
diff options
context:
space:
mode:
authorXiao Pan <gky44px1999@gmail.com>2024-02-23 03:08:52 -0800
committerXiao Pan <gky44px1999@gmail.com>2024-02-23 03:08:52 -0800
commitdd78faaf40862bd1552ec36c41374b527f747284 (patch)
treeb914f890c545db7168984f7bcc15cfc7c976c1d3 /sh/o
parentc808bb6ee7f77f077308a1f06f63dbee6a928f6d (diff)
Reorganize shell scripts into sh dir, consider in the future fsh will have different kinds of files
Diffstat (limited to 'sh/o')
-rwxr-xr-xsh/o27
1 files changed, 27 insertions, 0 deletions
diff --git a/sh/o b/sh/o
new file mode 100755
index 0000000..8fb066c
--- /dev/null
+++ b/sh/o
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# useful links
+# https://stackoverflow.com/questions/3430330/best-way-to-make-a-shell-script-daemon
+# https://serverfault.com/questions/117152/do-background-processes-get-a-sighup-when-logging-off
+# https://wiki.archlinux.org/title/default_applications
+
+# I don't care about errors, I don't want to handle errors, just shut up please.
+# nohup seems not necessary if don't care about daemon SIGHUP requirement
+
+# when close a shell script's stdout or stderr with `>&-` or `2>&-`, `xsel -ib` in that script has no effect
+# https://github.com/kfish/xsel/issues/43
+# using `>&-` or `2>&-` doesn't completely close mpv's output when run sth. like `o mpv file.mkv`
+# base on above observations, I choose to use `>/dev/null 2>&1` instead
+
+# need ; before } when it is in the same line as { ? https://www.shellcheck.net/wiki/SC1056
+
+if [ $# -eq 1 ] && [ -e "$1" ] && { ! [ -x "$1" ] || [ -d "$1" ];}; then
+ case "$1" in
+ # libreoffice, please don't let firefox eat your shit
+ *.docx|*.pptx) cmd=libreoffice;;
+ *) cmd=xdg-open;;
+ esac
+ nohup "$cmd" "$1" 0<&- >/dev/null 2>&1 &
+else
+ nohup "$@" 0<&- >/dev/null 2>&1 &
+fi