summary refs log tree commit diff
path: root/bin/swx
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2021-07-29 23:45:43 +0200
committerRobert Günzler <r@gnzler.io>2021-07-29 23:48:28 +0200
commite77881a72b735ca12aa055054656afdfbd6a8fc8 (patch)
tree53ed4778acca18f55141e4efbdc0a841b64116a5 /bin/swx
parent3079e935c793a9aa1831fd165e28636eb7a87dae (diff)
bin: format scripts
Diffstat (limited to 'bin/swx')
-rwxr-xr-xbin/swx141
1 files changed, 76 insertions, 65 deletions
diff --git a/bin/swx b/bin/swx
index 01003fc..1ba942b 100755
--- a/bin/swx
+++ b/bin/swx
@@ -30,55 +30,59 @@ mark=
 term_title=
 while getopts b:w:o:g:I:r:stfF:aSM:T:h name; do
 	case "$name" in
-	b)	# border
-		border="${OPTARG}" ;;
-	w)	# move to workspace
-		wspace="${OPTARG}" ;;
-	o)	# move to output
-		output="${OPTARG}" ;;
-	g)	# geometry
-		geometry="${OPTARG}" ;;
-	t)	# termify
-		termify=1 ;;
-	r)	# rotate
-		if ! command -v cage >/dev/null; then
-			printf "%s: cage not installed but required to rotate containers" "$0" >&2
-			exit 1
-		fi
-		rotate="${OPTARG}" ;;
-	s)	# set container to sticky
-		sticky=1 ;;
-	f)      # set container to float
-		floating=1 ;;
-	F)
-		floating="${OPTARG}" ;;
-	a)	# auto-tiling enabled
-		autotile=1 ;;
-	S)	# launch into scratchpad
-		into_scratchpad=1 ;;
-	M)	# mark
-		mark="${OPTARG}" ;;
-	T)	# set terminal title
-		term_title="${OPTARG}" ;;
+		b) # border
+			border="${OPTARG}" ;;
+		w) # move to workspace
+			wspace="${OPTARG}" ;;
+		o) # move to output
+			output="${OPTARG}" ;;
+		g) # geometry
+			geometry="${OPTARG}" ;;
+		t) # termify
+			termify=1 ;;
+		r) # rotate
+			if ! command -v cage >/dev/null; then
+				printf "%s: cage not installed but required to rotate containers" "$0" >&2
+				exit 1
+			fi
+			rotate="${OPTARG}"
+			;;
+		s) # set container to sticky
+			sticky=1 ;;
+		f) # set container to float
+			floating=1 ;;
+		F)
+			floating="${OPTARG}"
+			;;
+		a) # auto-tiling enabled
+			autotile=1 ;;
+		S) # launch into scratchpad
+			into_scratchpad=1 ;;
+		M) # mark
+			mark="${OPTARG}" ;;
+		T) # set terminal title
+			term_title="${OPTARG}" ;;
 
-	h|?)	printf "usage: %s [-bwogIrsfoSMT] COMMAND\n" "$(basename "$0")"
-		printf "\n"
-		printf "  -t \t\trun COMMAND in \$TERM\n"
-		printf "  -b BORDER \tset border property\n"
-		printf "  -w WORKSPACE \tmove to workspace\n"
-		printf "  -o OUTPUT \tmove to output\n"
-		printf "  -g GEOMETRY \tresize/position window\n"
-		printf "  -r ROTATION \trotate the container, requires cage(1)\n"
-		printf "  -s \t\tmake COMMAND a sticky window, appearing on all workspaces\n"
-		printf "  -f \t\tmake COMMAND a floating window\n"
-		printf "  -F OPTIONS\tmake COMMAND a floating window\n\t\tsee centercon(1) for possible options\n"
-		printf "  -a \t\tauto-tiling; always open COMMAND on the shorter edge of\n\t\tthe current container\n"
-		printf "  -S \t\tmove the container into the scratchpad\n"
-		printf "  -M MARK\t\set MARK on the container\n"
-		printf "  -T TERM_TITLE\t\set a title on the terminal (only makes sense with -t)\n"
-		printf "\n"
-		printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n"
-		exit 2 ;;
+		h | ?)
+			printf "usage: %s [-bwogIrsfoSMT] COMMAND\n" "$(basename "$0")"
+			printf "\n"
+			printf "  -t \t\trun COMMAND in \$TERM\n"
+			printf "  -b BORDER \tset border property\n"
+			printf "  -w WORKSPACE \tmove to workspace\n"
+			printf "  -o OUTPUT \tmove to output\n"
+			printf "  -g GEOMETRY \tresize/position window\n"
+			printf "  -r ROTATION \trotate the container, requires cage(1)\n"
+			printf "  -s \t\tmake COMMAND a sticky window, appearing on all workspaces\n"
+			printf "  -f \t\tmake COMMAND a floating window\n"
+			printf "  -F OPTIONS\tmake COMMAND a floating window\n\t\tsee centercon(1) for possible options\n"
+			printf "  -a \t\tauto-tiling; always open COMMAND on the shorter edge of\n\t\tthe current container\n"
+			printf "  -S \t\tmove the container into the scratchpad\n"
+			printf "  -M MARK\t\set MARK on the container\n"
+			printf "  -T TERM_TITLE\t\set a title on the terminal (only makes sense with -t)\n"
+			printf "\n"
+			printf "See sway(5) for possible options for BORDER, WORKSPACE, OUTPUT and GEOMETRY.\n"
+			exit 2
+			;;
 	esac
 	# block until we have a con_id matching on pid of the spawned process
 	patience=1
@@ -93,15 +97,19 @@ shift
 
 command="${arg0} ${*}"
 
-# needs to be termified?
+# needs to be termified
 # spawn a $TERM instance and exec that
 if [ -n "${termify}" ]; then
-	case ${TERM:-foot} in
-	alacritty) term_args="--title=${term_title:-${arg0}} --class=${term_title:-${arg0}} --command" ;;
-	foot)      term_args="--title=${term_title:-${arg0}} --app-id=${term_title:-${arg0}} --" ;;
-	*)         term_args="" ;;
-	esac
-	command="${TERM} ${term_args} ${command}"
+	if [ -n "${floating}" ]; then
+		term_args="floaterm"
+	else
+		term_args="foot"
+	fi
+	term_args="${term_args} --title=${term_title:-${arg0}} --app-id=${term_title:-${arg0}}"
+	if [ -n "${SWX_TERM_ARGS}" ]; then
+		term_args="${term_args} ${SWX_TERM_ARGS}"
+	fi
+	command="${term_args} -- ${command}"
 fi
 
 # needs to be rotated
@@ -109,7 +117,7 @@ fi
 if [ -n "${rotate}" ]; then
 	# figure out how many "-r" flags we need
 	rotate_args=""
-	while [ $(( (rotate / 90) >= 1 )) = 1 ]; do
+	while [ $(((rotate / 90) >= 1)) = 1 ]; do
 		rotate_args="${rotate_args} -r"
 		rotate=$((rotate - 90))
 	done
@@ -124,21 +132,24 @@ fi
 
 if [ -n "${autotile}" ]; then
 	layout=$(swq current con | jq -r '.layout')
-	 # layout=$(swq current workspace | jq -r '.. | select(.type?=="con" and .name?==null) | .layout')
+	# layout=$(swq current workspace | jq -r '.. | select(.type?=="con" and .name?==null) | .layout')
 	# notify-send swx "${layout}"
 	case "${layout}" in
-	split*)
-		if [ "$(swq current con | jq '.rect | .width > .height')" = "true" ]; then
-			swaymsg splith
-		else
-			swaymsg splitv
-		fi
-		;;
+		split*)
+			if [ "$(swq current con | jq '.rect | .width > .height')" = "true" ]; then
+				swaymsg splith
+			else
+				swaymsg splitv
+			fi
+			;;
 	esac
 fi
 
 swaymsg exec -- "${command}" >/dev/null
-[ $? ] || { printf "error: failed to spawn \"${command}\"\n"; exit 1; }
+[ $? ] || {
+	printf "error: failed to spawn \"${command}\"\n"
+	exit 1
+}
 [ -z "$patience" ] && exit 0
 # waiting for container to appear
 con_id="$(swaymsg -t subscribe '["window"]' | jq -s '.[]|select(.change=="new")|.container.id')"