djcev.com

//

Git Repos / dotfiles / bin / hc_swap.sh

Last update to this file was on 2024-01-02 at 05:12.

Show hc_swap.sh

#!/bin/sh
#
# Copyright (c) 2015-2021, Cameron Vanderzanden. Available under the
# terms of the 2-clause BSD license. Please see the file "LICENSE" in
# the root dir of this repository for more information.
#
#- hc_swap.sh 2015/01/06 cev, last updated 2021/12/07.
## Usage: hc_swap.sh [-hV] <direction>
##
## Swap the currently selected window with the window in <direction>.
## Valid directions are: left, right, up, down.
##
## Based on a script by Caleb Everett, available at:
## https://github.com/everett1992/herbstluftwm/blob/master/swap
#
# Script logic is fundamentally unchanged from everett1992's version.
# All I've done is throw a bunch of junk in.

[ -x $HOME/.local/bin/cev_print.sh ] && . $HOME/.local/bin/cev_print.sh

self="${0##*'/'}"
dir=""

die_invalid_argument() {
print_self error
printf "%binvalid argument.%b\n" "$_norm" "$_clear" >&2
exit 1
}

die_invalid_direction() {
print_self error
printf "%binvalid direction.%b\n" "$_norm" "$_clear" >&2
exit 1
}

hc() { herbstclient "$@"; }
lock() { hc lock; }
unlock() { hc unlock; }

while getopts "hV?" option; do
case $option in
h) print_help && exit ;;
V) print_version && exit ;;
"?") print_help && exit ;;
esac
shift $((OPTIND - 1))
done

[ $# -lt 1 ] && die_invalid_argument

case $1 in
"left" | "right" | "up" | "down") dir="$1" ;;
*) die_invalid_direction ;;
esac

srcwinid=$(hc attr clients.focus.winid) # source window ID; "from"
hc focus $dir 2>/dev/null # move to our destination window
if [ $? -ne 0 ]; then exit 1; fi # abort if unable to focus in that dir.
dstwinid=$(hc attr clients.focus.winid) # destination window ID; "to"
swpexp="s/$srcwinid/TOKEN/g; s/$dstwinid/$srcwinid/g; s/TOKEN/$dstwinid/g"
hc load "$(hc dump | sed -e "$swpexp")" # alter the window layout.

Return to the top of this page or return to the overview of this repo.

Log hc_swap.sh

Date Commit Message Author + -
2024-01-02 Change from FreeBSD to Linux, other minor changes cev +1 -1
2021-12-13 Expanded redshift background.sh, misc. changes cev +1 -1
2021-12-08 Initial commit. Dotfiles, scripts, basic Makefile. cev +61  

Return to the top of this page or return to the overview of this repo.