if (word(2 $loadinfo()) != 'pf') {
	load -pf $word(1 $loadinfo());
	return;
};

#	Copyright 2007 EPIC Software Labs
#	Written by BlackJac@EFNet
#
#	Version: 2.0.2007.03.16.1
#
#	This script will allow you to switch between your hidden windows more
#	easily. Press Alt+<number> or Esc+<number> (depending on your terminal
#	application) to switch to hidden window <number>. If you are in hidden
#	window 5 and you press Alt+5, you will go to window 15, then 25, etc.
#	(assuming those windows exist), until you cycle back to window 5. You
#	may also use Alt+? to be prompted for a window number. Press Alt+- or
#	Alt+= to cycle through the previous or next windows, respectively.

package altchan;

alias altchan.input (void) {
	input "$banner Switch to which window \(currently $winnum()\)? " {
		if (strlen($*)) {
			altchan.toggle $0;
		};
	};
};

alias altchan.toggle (number, void) {
	if (number) {
		if (number == winnum()) {
			@ :window = number + 10;
			if (winnum($window) != -1) {
				window refnum_or_swap $window;
			} else {
				xecho -b -c Window $window does not exist;
			};
		} else if (number == right(1 $winnum())) {
			@ :window = winnum() + 10;
			if (winnum($window) != -1) {
				window refnum_or_swap $window;
			} else if (winnum($number) != -1) {
				window refnum_or_swap $number;
			} else {
				xecho -b -c Windows $window and $number do not exist;
			};
		} else {
			if (winnum($number) != -1) {
				window refnum_or_swap $number;
			} else {
				xecho -b -c Window $number does not exist;
			};
		};
	};
};

@ bindctl(sequence ^[0 set parse_command altchan.toggle 10);
fe ($jot(1 9 1)) aa {
	@ bindctl(sequence ^[$aa set parse_command altchan.toggle $aa);
	alias $aa altchan.toggle $aa;
};
@ bindctl(sequence ^[- set parse_command window previous);
@ bindctl(sequence ^[= set parse_command window next);
@ bindctl(sequence ^[? set parse_command altchan.input);
