From 1a5ad4a82ca79ca693ee5fbed3478ab20fbedadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 18 Jun 2021 21:04:36 +0200 Subject: xtopen: Add -k option (keep open) --- xtopen | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'xtopen') diff --git a/xtopen b/xtopen index 540f4bd..83bca60 100755 --- a/xtopen +++ b/xtopen @@ -14,18 +14,22 @@ abbr() { if [ $# -eq 0 ]; then xmessage -buttons sorry:0 -default sorry -nearmouse \ - "usage: $0 [-K] cmd ..." + "usage: $0 [-k] [-K] cmd ..." exit 1 fi -flagK= -case "$1" in --K) flagK=-K - shift ;; --*) xmessage -buttons sorry:0 -default sorry -nearmouse \ - error: "unknown flag $1" - exit 1 ;; -esac +k= +K= +while getopts kK o; do + case $o in + K) K=1 ;; + k) k=1 ;; + ?) xmessage -buttons sorry:0 -default sorry -nearmouse \ + error: "unknown flag $1" + exit 1 ;; + esac +done +shift $((OPTIND-1)) if ! which "$1" 2>/dev/null; then xmessage -default okay -nearmouse \ @@ -33,6 +37,8 @@ if ! which "$1" 2>/dev/null; then exit 1 fi -[ -z "$flagK" ] && -exec xterm -title "$* (`abbr "$PWD"`)" -e "$@" || -exec xterm -title "$* (`abbr "$PWD"`)" -e with-shell-on-error "$@" +case "$k,$K" in +1,*) exec xterm -title "$* (`abbr "$PWD"`)" -e with-shell "$@" ;; +*,1) exec xterm -title "$* (`abbr "$PWD"`)" -e with-shell-on-error "$@" ;; +*,*) exec xterm -title "$* (`abbr "$PWD"`)" -e "$@" ;; +esac -- cgit v1.2.3