Hi, On Tue, Nov 06, 2012 at 03:42:58PM +0900, Kazuhiko Sakaguchi wrote: > I created and moved a pane-maximize repository on GitHub. > https://github.com/pi8027/pane-maximize
I took a look at this, since I'm quite keen to ensure that if this script or one like it is to replace the current "tmux-zoom.sh" script, that it actually works this time. I can't quite see how your script does work though, so I've got some questions: > #!/bin/bash #!/usr/bin/env bash (For those people on BSD where /bin/bash is not guaranteed.) > # By Kazuhiko Sakaguchi. Public domain. > > function usage_exit(){ > cat <<EOT > Usage: $(echo $0 | sed "s/.*\///") [-adP] [-F format] [-t target-pane] Why not using "basename" here? > -a, -d, -P, -F format: these options are passed to tmux new-window > -t target-pane: specify target pane > EOT > exit $1 I think you should just exit 1 here, and not worry about passing in some value for this. Note also though that most help information is sent to STDERR as good practice. Hence: cat <<FOO >&2 ... ... FOO > } > > paneid=$(tmux display-message -p '#{pane_id}') > > optflag_a=false > nwopts= > > while getopts adPF:t: OPT ; do > case $OPT in > t ) paneid=$OPTARG ;; > a ) optflag_a=true ;; > d|P) nwopts="-$OPT $nwopts" ;; > F ) nwopts="-F $OPTARG $nwopts" ;; > * ) usage_exit -1 ;; > esac > done > > paneid=$(tmux display-message -t $paneid -p '#{pane_id}' || exit -1) Trampling paneid again here, probably isn't what you want to do. The "exit -1" in the subshell here is a very odd thing to do in the case where there's no return value. Indeed, if it is to have a value after being trampled, then it should be written like this: paneid=$(...) [ -z "$paneid" ] && { echo "Oops, something went wrong" >&2 exit 1 } > winid=$(tmux display-message -t $paneid -p '#{window_id}') > pmtable=$(tmux showenv pmtable | sed 's/^pmtable=//') When I get here, having run your script for the first time, I get an error from tmux that "pmtable" has no value. This is indeed true, and in such cases when this happens, the rest of your script fails to run because the entirety of it assumes this "pmtable" value to have some value. Perhaps: pmtable=$(tmux showenv pmtable 2>/dev/null | sed 's/^pmtable=//') > $optflag_a && nwopts="-a -t $winid $nwopts" It is perhaps preferrable to not treat optflag_a as some literal boolean, but rather use something like: [ -n "$optflag_a" ] && nwopts="-a -t $winid $nwopts" > if target=$(echo $pmtable | tr : "\n" | \ > grep -E "(=|^)$paneid(=|$)" | head -n 1 | grep .) ; then Ugh. :) What is this trying to do? (I know what it's doing, it's a rhetorical question). At this point, the "if" condition is wholly incorrect. I suggest this: target=$(echo $pmtable | tr : "\n" | \ grep -E "(=|^)$paneid(=|$)" | head -n 1 | grep .) if [ -n "$target" ]; then > IFS== ; set -- $target ; IFS=' ' ; \ Setting "IFS==" here makes no sense. > tmux swap-pane -t $2 -s $1 \; \ > kill-pane -t $2 \; \ > setenv pmtable "$(echo $pmtable | sed "s/:$target//")" > elif [ $(tmux list-panes -t $winid -F '' | wc -l) != 1 ] ; then Why "-F ''"? > tmux new-window $nwopts "\"$0-sub\" $paneid" > else > tmux display-message "This pane is already maximized." > fi -- Thomas Adam ------------------------------------------------------------------------------ LogMeIn Central: Instant, anywhere, Remote PC access and management. Stay in control, update software, and manage PCs from one command center Diagnose problems and improve visibility into emerging IT issues Automate, monitor and manage. Do more in less time with Central http://p.sf.net/sfu/logmein12331_d2d _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users