diff --git a/CHANGELOG.md b/CHANGELOG.md index 0deefa8..789f53f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ Versioning complies with [semantic versioning (semver)](http://semver.org/). +* **[v0.5.0](https://github.com/mklement0/ttab/compare/v0.4.0...v0.5.0)** (2016-10-01): + * [new feature] `-q` now allows clearing the "screen" of the new tab after + opening using `clear`, assuming any command (list) passed succeeded. + * [enhancement] A quoted multi-command shell command string can now be + specified as a single - and only - operand, without having to precede with + an explicit `eval` command. + * [behavior change] If no custom title is specified with `-t `, no + attempt is made anymore to auto-derive a meaningful tab title from the + shell command specified, as there is no heuristic that works well in all + cases. + * [fix] [Issue #7](https://github.com/mklement0/ttab/issues/7): iTerm2 + now also preserves the current working dir. when opening a new tab in the + current window. + * **[v0.4.0](https://github.com/mklement0/ttab/compare/v0.3.1...v0.4.0)** (2016-09-13): * [enhancement] `-a Terminal|iTerm2` now allows specifying the target Terminal application, which is useful for launching `ttab` from non-terminal applications diff --git a/README.md b/README.md index 78d4c8a..1d1b792 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ # ttab — open a new Terminal.app / iTerm2.app tab or window -An [OS X](https://www.apple.com/osx/) CLI for programmatically opening a new terminal tab/window in the standard terminal application, `Terminal`, +A [macOS (OS X)](https://www.apple.com/osx/) CLI for programmatically opening a new terminal tab/window in the standard terminal application, `Terminal`, or in popular alternative [`iTerm2`](http://www.iterm2.com/), optionally with a command to execute and/or a specific title and specific display settings. Note: `iTerm2` support is experimental in that it is currently not covered by the automated tests run before every release. @@ -62,6 +62,10 @@ ttab -w # Open a new tab and execute the specified command before showing the prompt. ttab ls -l "$HOME/Library/Application Support" +# Open a new tab and execute *multiple* commands in it - note how the entire +# command line is specified as *single, quoted string*. +ttab -t 'git branch; git status' + # Open a new tab, switch to the specified dir., then execute the specified # command before showing the prompt. ttab -d ~/Library/Application\ Support ls -1 @@ -76,7 +80,7 @@ ttab /path/to/someScript ttab exec /path/to/someScript # Open a new tab, execute a command, wait for a keypress, and exit. -ttab eval 'ls "$HOME/Library/Application Support"; echo Press a key to exit.; read -rsn 1; exit' +ttab 'ls "$HOME/Library/Application Support"; echo Press a key to exit.; read -rsn 1; exit' # Open a new tab in iTerm2 (if installed). ttab -a iTerm2 echo 'Hi from iTerm2.' @@ -94,16 +98,18 @@ $ ttab --help Opens a new terminal tab or window in OS X's Terminal application or iTerm2. - ttab [-w] [-s <settings>] [-t <title>] [-g|-G] [-d <dir>] [<cmd> [<arg>...]] + ttab [-w] [-s <settings>] [-t <title>] [-q] [-g|-G] [-d <dir>] [<cmd> ...] -w open new tab in new terminal window -s <settings> assign a settings set (profile) -t <title> specify title for new tab + -q clear the new tab's screen -g create tab in background (don't activate Terminal/iTerm) -G create tab in background and don't activate new tab -d <dir> specify working directory -a Terminal|iTerm2 open tab or window in Terminal.app / iTerm2 - <cmd> [<arg>...] command to execute in the new tab + <cmd> ... command to execute in the new tab + "<cmd> ...; ..." multi-command command line (passed as single operand) Standard options: --help, --man, --version, --home ``` @@ -140,6 +146,20 @@ Versioning complies with [semantic versioning (semver)](http://semver.org/). <!-- NOTE: An entry template for a new version is automatically added each time `make version` is called. Fill in changes afterwards. --> +* **[v0.5.0](https://github.com/mklement0/ttab/compare/v0.4.0...v0.5.0)** (2016-10-01): + * [new feature] `-q` now allows clearing the "screen" of the new tab after + opening using `clear`, assuming any command (list) passed succeeded. + * [enhancement] A quoted multi-command shell command string can now be + specified as a single - and only - operand, without having to precede with + an explicit `eval` command. + * [behavior change] If no custom title is specified with `-t <title>`, no + attempt is made anymore to auto-derive a meaningful tab title from the + shell command specified, as there is no heuristic that works well in all + cases. + * [fix] [Issue #7](https://github.com/mklement0/ttab/issues/7): iTerm2 + now also preserves the current working dir. when opening a new tab in the + current window. + * **[v0.4.0](https://github.com/mklement0/ttab/compare/v0.3.1...v0.4.0)** (2016-09-13): * [enhancement] `-a Terminal|iTerm2` now allows specifying the target Terminal application, which is useful for launching `ttab` from non-terminal applications diff --git a/bin/ttab b/bin/ttab index 30ac2ba..a6fc01b 100755 --- a/bin/ttab +++ b/bin/ttab @@ -2,7 +2,7 @@ kTHIS_HOMEPAGE='https://github.com/mklement0/ttab' kTHIS_NAME=${BASH_SOURCE##*/} -kTHIS_VERSION='v0.4.0' # NOTE: This assignment is automatically updated by `make version VER=<newVer>` - DO keep the 'v' prefix. +kTHIS_VERSION='v0.5.0' # NOTE: This assignment is automatically updated by `make version VER=<newVer>` - DO keep the 'v' prefix. unset CDPATH # To prevent unexpected `cd` behavior. @@ -92,9 +92,11 @@ dirAbs='' tabTitle='' settingsName='' inBackground=0 +targetTermSpecified=0 inNewWin=0 +cls=0 terminalApp="$TERM_PROGRAM" # default to the terminal program that is running this script -while getopts ':wgGs:t:d:a:' opt; do # $opt will receive the option *letters* one by one; a trailing : means that an arg. is required, reported in $OPTARG. +while getopts ':wgGqs:t:d:a:' opt; do # $opt will receive the option *letters* one by one; a trailing : means that an arg. is required, reported in $OPTARG. [[ $opt == '?' ]] && dieSyntax "Unknown option: -$OPTARG" [[ $opt == ':' ]] && dieSyntax "Option -$OPTARG is missing its argument." case "$opt" in @@ -113,6 +115,7 @@ while getopts ':wgGs:t:d:a:' opt; do # $opt will receive the option *letters* o ;; a) terminalApp=$OPTARG + targetTermSpecified=1 ;; g) inBackground=1 @@ -120,6 +123,9 @@ while getopts ':wgGs:t:d:a:' opt; do # $opt will receive the option *letters* o G) inBackground=2 ;; + q) + cls=1 + ;; *) # An unrecognized switch. dieSyntax "DESIGN ERROR: unanticipated option: $opt" ;; @@ -262,7 +268,6 @@ if (( inBackground )); then delay 0.1 end repeat' else # foreground operation (backgrounding with -g or -G NOT requested) - we activate explicitly, so as to support invocation from helper apps such as Alfred where the terminal may be created implicitly and not gain focus by default. - # CMD_ACTIVATE = 'activate'x CMD_ACTIVATE='activate repeat until frontmost delay 0.1 @@ -271,42 +276,69 @@ fi # Optional commands that are only used if the relevant options were specified. quotedShellCmds='' -if (( $# )); then # Shell command(s) specified. - - if [[ -z $tabTitle ]]; then # no explicit title specified - # Use the command's first token as the tab title. - tabTitle=$1 - case "$tabTitle" in - exec|eval) # Use following token instead, if the 1st one is 'eval' or 'exec'. - tabTitle=$(echo "$2" | awk '{ print $1 }') - ;; - cd) # Use last path component of following token instead, if the 1st one is 'cd' - tabTitle=$(basename "$2") - ;; - esac +shellCmdTokens=( "$@" ) +if (( ${#shellCmdTokens[@]} )); then # Shell command(s) specified. + + if (( ${#shellCmdTokens[@]} == 1 )); then # Could be a mere command name like 'ls' or a multi-command string such as 'git bash && git status' + # If only a single string was specified as the command to execute in the new tab: + # It could either be a *mere command name* OR a *quoted string containing MULTIPLE commands*. + # We use `type` to determine if it is a mere command name / executable in the + # current dir., otherwise we assume that the operand is a multi-command string + # in which case we must use `eval` to execute it. + # Note: Blindly prepending `eval` would work in MOST, but NOT ALL cases, + # such as with commands whose names happen to contain substrings + # that look like variable references (however rare that may be). + ([[ -n $dirAbs ]] && cd "$dirAbs"; type "${shellCmdTokens[0]}" &>/dev/null) || shellCmdTokens=( 'eval' "${shellCmdTokens[@]}" ) fi # The tricky part is to quote the command tokens properly when passing them to AppleScript: # Quote all parameters (as needed) using printf '%q' - this will perform backslash-escaping. # This will allow us to not have to deal with double quotes inside the double-quoted string that will be passed to `do script`. - quotedShellCmds=$(printf ' %q' "$@") # note: we'll end up with a leading space, but that's benign (a *trailing* space would be a problem with iTerm's write <session> text ... command) - -fi - - # If no directory was specified, we explicitly use the *current* working directory, - # if we're called from *inside a script*. - # Rationale: Terminal.app only knows the working directory of the *top-level* shell running in each tab (as it defines an aux. function, - # update_terminal_cwd(), that is called via $PROMPT_COMMAND every time the prompt is displayed). - # Thus, when this script is invoked inside another script, it is the *top-level* shell's working directory that is invariably used by - # Terminal, even if the invoking script has changed the working directory. Since this is counter-intuitive, we compensate here - # by explicitly setting the working directory to the invoking script's with a prepended 'cd' command. - # $SHLVL tells us the nesting level of the current shell: - # 1 == top-level shell; since this script itself runs in a subshell (2, if invoked directly from the top-level shell), we can safely assume - # that another *script* has invoked us, if $SHLVL >= 3. - # Furthermore, we want to exhibit the same behavior when creating a tab in a *new* window, whereas Terminal defaults to the home directory - # in that case - thus, regardless of $SHLVL, if -w is specified, we always use an explicit 'cd' command. -if [[ -z $dirAbs && ($inNewWin -eq 1 || $SHLVL -ge 3) ]]; then - dirAbs=$PWD + quotedShellCmds=$(printf ' %q' "${shellCmdTokens[@]}") + # Note: $quotedShellCmds now has a leading space, but that's benign (a *trailing* space, by contrast, would be a problem with iTerm's `write <session> text ...` command) + + # !! [AUTO-DERIVING A TAB TITLE DISABLED - there's ultimately no heuristic that's guaranteed to result in a meaningful title. Let users specify a title explicitly, if needed. ] + # # If no title was specified, derive it from the command specified. + # if [[ -z $tabTitle ]]; then # no explicit title specified + # # Use the command's first (meaningful) token as the tab title. + # i=0 + # [[ ${shellCmdTokens[i]} =~ ^exec|eval$ ]] && (( ++i )) + # [[ ${shellCmdTokens[i]} == cd ]] && (( ++i )) + # tabTitle=$(printf %s "${shellCmdTokens[i]}" | tr -d '\\"') + # fi + +fi # if (( ${#shellCmdTokens[@]} ) + +# Note: The desired behavior is to ALWAYS OPEN A TAB IN THE DIRECTORY THE CALLER +# CONSIDERS CURRENT, whether the new tab is being opened in the current or +# a new window (unless a target dir. is explicitly specified with -d <dir>). +# Terminal and iTerm have different default behaviors, so we need to account for +# that: +# * When opening a tab in a new *window*, both Terminal and iTerm default to the *home* dir. +# * When opening a new in the current window, +# * Terminal: the *caller's currrent dir., as known to Terminal* (see below) is used. +# Also, to be safe, if a target terminal is explicitly specified, we also +# default to issuing a `cd` command, because it might be a different terminal than the current one. +if (( iTerm || targetTermSpecified )); then + # iTerm2 always defaults to the home dir., so we must always add an explicit `cd` command to ensure that the current dir. is used. + if [[ -z $dirAbs ]]; then + dirAbs=$PWD + fi +else + # While Terminal.app does default to the caller's current dir. when creating a tab + # in the *current* window, it doesn't necessarily know the *immediate caller's* true $PWD, + # so we have to compensate for that"" + # Terminal.app only knows the working directory of the *top-level* shell running in each tab (as it defines an aux. function, + # update_terminal_cwd(), that is called via $PROMPT_COMMAND every time the prompt is displayed). + # Thus, when this script is invoked inside another script, it is the *top-level* shell's working directory that is invariably used by + # Terminal, even if the invoking script has changed the working directory. Since this is counter-intuitive, we compensate here + # by explicitly setting the working directory to the invoking script's with a prepended 'cd' command. + # $SHLVL tells us the nesting level of the current shell: + # 1 == top-level shell; since this script itself runs in a subshell (2, if invoked directly from the top-level shell), we can safely assume + # that another *script* has invoked us, if $SHLVL >= 3. + if [[ -z $dirAbs && ($SHLVL -ge 3 || $inNewWin -eq 1) ]]; then + dirAbs=$PWD + fi fi # Prepend the 'cd' command, if specified or needed. @@ -319,12 +351,22 @@ if [[ -n $dirAbs ]]; then fi fi +# Append the 'clear' command, if requested. +if (( cls )); then + if [[ -n $quotedShellCmds ]]; then + quotedShellCmds="$quotedShellCmds && clear" + else + quotedShellCmds='clear' + fi +fi + + # Synthesize the full shell command. if [[ -n $quotedShellCmds ]]; then # Pass the commands as a single AppleScript string, of necessity double-quoted. # For the benefit of AppleScript # - embedded backslashes must be escaped by doubling them - # - embedded doubleq quotes must be backlash-escaped + # - embedded double quotes must be backlash-escaped quotedShellCmdsForAppleScript=${quotedShellCmds//\\/\\\\} quotedShellCmdsForAppleScript=${quotedShellCmdsForAppleScript//\"/\\\"} if (( iTerm )); then @@ -338,14 +380,19 @@ if [[ -n $quotedShellCmds ]]; then fi fi -if [[ -n $tabTitle ]]; then +if [[ -n $tabTitle ]]; then # custom tab title specified + # For the benefit of AppleScript + # - embedded backslashes must be escaped by doubling them + # - embedded double quotes must be backlash-escaped + tabTitle=${tabTitle//\\/\\\\} + tabTitle=${tabTitle//\"/\\\"} if (( iTerm )); then if (( iTermOld )); then # OLD iTerm syntax (v2-) CMD_TITLE="tell current session of current terminal to set name to \"$tabTitle\"" else # NEW iTerm syntax (introduced in v3) CMD_TITLE="tell current session of current window to set name to \"$tabTitle\"" fi - else + else # Terminal.app CMD_TITLE="set custom title of newTab to \"$tabTitle\"" fi fi @@ -424,16 +471,18 @@ exec osascript <<<"$script" Opens a new terminal tab or window in OS X's Terminal application or iTerm2. - ttab [-w] [-s <settings>] [-t <title>] [-g|-G] [-d <dir>] [<cmd> [<arg>...]] + ttab [-w] [-s <settings>] [-t <title>] [-q] [-g|-G] [-d <dir>] [<cmd> ...] -w open new tab in new terminal window -s <settings> assign a settings set (profile) -t <title> specify title for new tab + -q clear the new tab's screen -g create tab in background (don't activate Terminal/iTerm) -G create tab in background and don't activate new tab -d <dir> specify working directory -a Terminal|iTerm2 open tab or window in Terminal.app / iTerm2 - <cmd> [<arg>...] command to execute in the new tab + <cmd> ... command to execute in the new tab + "<cmd> ...; ..." multi-command command line (passed as single operand) Standard options: `--help`, `--man`, `--version`, `--home` @@ -462,9 +511,7 @@ Prefix such a single command with `exec` to exit the shell after the command terminates. If the tab's settings are configured to close tabs on termination of the shell, the tab will close automatically. -To specify *multiple* commands, use `eval` followed by a single, quoted -string containing the entire shell command line to execute; in the simplest -case, enclose the string in single-quotes and use ';' to separate commands. +To specify *multiple* commands, pass them as a *single, quoted string*. Use `exit` as the last command to automatically close the tab when the command terminates, assuming the tab's settings are configured to close the tab on termination of the shell. @@ -496,6 +543,12 @@ Precede `exit` with `read -rsn 1` to wait for a keystroke first. invoking shell's working directory is inherited (even if `-w` is also specified). + * `-q` + (*q*uiet) issues a `clear` command after opening the new tab. + Note that output will temporarily be visible while the tab is being opened; + also, clearing is not performed if any command passed reports an overall + nonzero exit code, so as to allow failures to be examined. + * `-g` (back*g*round) causes Terminal/iTerm2 not to activate, if it isn't the frontmost application); within the application, however, the new tab will @@ -561,8 +614,9 @@ For license information and more, visit this utility's home page by running # If configured via the default profile, also close the tab. ttab exec /path/to/someprogram arg1 arg2 - # Pass a multi-command string via 'eval', wait for a keystroke, then exit. - ttab eval 'ls "$HOME/Library/Application Support"; + # Pass a multi-command string as a single, quoted string, wait for a + # keystroke, then exit. + ttab 'ls "$HOME/Library/Application Support"; echo Press any key to exit; read -rsn 1; exit' # Create a new tab explicitly in iTerm2. diff --git a/doc/ttab.md b/doc/ttab.md index 9840ee3..595815e 100644 --- a/doc/ttab.md +++ b/doc/ttab.md @@ -6,16 +6,18 @@ Opens a new terminal tab or window in OS X's Terminal application or iTerm2. - ttab [-w] [-s <settings>] [-t <title>] [-g|-G] [-d <dir>] [<cmd> [<arg>...]] + ttab [-w] [-s <settings>] [-t <title>] [-q] [-g|-G] [-d <dir>] [<cmd> ...] -w open new tab in new terminal window -s <settings> assign a settings set (profile) -t <title> specify title for new tab + -q clear the new tab's screen -g create tab in background (don't activate Terminal/iTerm) -G create tab in background and don't activate new tab -d <dir> specify working directory -a Terminal|iTerm2 open tab or window in Terminal.app / iTerm2 - <cmd> [<arg>...] command to execute in the new tab + <cmd> ... command to execute in the new tab + "<cmd> ...; ..." multi-command command line (passed as single operand) Standard options: `--help`, `--man`, `--version`, `--home` @@ -44,9 +46,7 @@ Prefix such a single command with `exec` to exit the shell after the command terminates. If the tab's settings are configured to close tabs on termination of the shell, the tab will close automatically. -To specify *multiple* commands, use `eval` followed by a single, quoted -string containing the entire shell command line to execute; in the simplest -case, enclose the string in single-quotes and use ';' to separate commands. +To specify *multiple* commands, pass them as a *single, quoted string*. Use `exit` as the last command to automatically close the tab when the command terminates, assuming the tab's settings are configured to close the tab on termination of the shell. @@ -78,6 +78,12 @@ Precede `exit` with `read -rsn 1` to wait for a keystroke first. invoking shell's working directory is inherited (even if `-w` is also specified). + * `-q` + (*q*uiet) issues a `clear` command after opening the new tab. + Note that output will temporarily be visible while the tab is being opened; + also, clearing is not performed if any command passed reports an overall + nonzero exit code, so as to allow failures to be examined. + * `-g` (back*g*round) causes Terminal/iTerm2 not to activate, if it isn't the frontmost application); within the application, however, the new tab will @@ -143,8 +149,9 @@ For license information and more, visit this utility's home page by running # If configured via the default profile, also close the tab. ttab exec /path/to/someprogram arg1 arg2 - # Pass a multi-command string via 'eval', wait for a keystroke, then exit. - ttab eval 'ls "$HOME/Library/Application Support"; + # Pass a multi-command string as a single, quoted string, wait for a + # keystroke, then exit. + ttab 'ls "$HOME/Library/Application Support"; echo Press any key to exit; read -rsn 1; exit' # Create a new tab explicitly in iTerm2. diff --git a/man/ttab.1 b/man/ttab.1 index 3aafb3e..316ac1b 100644 --- a/man/ttab.1 +++ b/man/ttab.1 @@ -1,4 +1,4 @@ -.TH "TTAB" "1" "September 2016" "v0.4.0" "" +.TH "TTAB" "1" "October 2016" "v0.5.0" "" .SH "NAME" \fBttab\fR \- open a new Terminal\.app / iTerm\.app tab or window .SH SYNOPSIS @@ -7,16 +7,18 @@ Opens a new terminal tab or window in OS X's Terminal application or iTerm2\. .P .RS 2 .nf -ttab [\-w] [\-s <settings>] [\-t <title>] [\-g|\-G] [\-d <dir>] [<cmd> [<arg>\.\.\.]] +ttab [\-w] [\-s <settings>] [\-t <title>] [\-q] [\-g|\-G] [\-d <dir>] [<cmd> \.\.\.] \-w open new tab in new terminal window \-s <settings> assign a settings set (profile) \-t <title> specify title for new tab +\-q clear the new tab's screen \-g create tab in background (don't activate Terminal/iTerm) \-G create tab in background and don't activate new tab \-d <dir> specify working directory \-a Terminal|iTerm2 open tab or window in Terminal\.app / iTerm2 -<cmd> [<arg>\.\.\.] command to execute in the new tab +<cmd> \.\.\. command to execute in the new tab +"<cmd> \.\.\.; \.\.\." multi\-command command line (passed as single operand) .fi .RE .P @@ -59,11 +61,7 @@ terminates\. If the tab's settings are configured to close tabs on termination .br of the shell, the tab will close automatically\. .P -To specify \fImultiple\fR commands, use \fBeval\fP followed by a single, quoted -.br -string containing the entire shell command line to execute; in the simplest -.br -case, enclose the string in single\-quotes and use ';' to separate commands\. +To specify \fImultiple\fR commands, pass them as a \fIsingle, quoted string\fR\|\. .br Use \fBexit\fP as the last command to automatically close the tab when the .br @@ -114,6 +112,16 @@ Precede \fBexit\fP with \fBread \-rsn 1\fP to wait for a keystroke first\. .br specified)\. .IP \(bu 2 +\fB\-q\fP +.br + (\fIq\fRuiet) issues a \fBclear\fP command after opening the new tab\. +.br + Note that output will temporarily be visible while the tab is being opened; +.br + also, clearing is not performed if any command passed reports an overall +.br + nonzero exit code, so as to allow failures to be examined\. +.IP \(bu 2 \fB\-g\fP .br (back\fIg\fRround) causes Terminal/iTerm2 not to activate, if it isn't the @@ -205,8 +213,9 @@ ttab \-d "$HOME/Library/Application Support" ls \-l # If configured via the default profile, also close the tab\. ttab exec /path/to/someprogram arg1 arg2 -# Pass a multi\-command string via 'eval', wait for a keystroke, then exit\. -ttab eval 'ls "$HOME/Library/Application Support"; +# Pass a multi\-command string as a single, quoted string, wait for a +# keystroke, then exit\. +ttab 'ls "$HOME/Library/Application Support"; echo Press any key to exit; read \-rsn 1; exit' # Create a new tab explicitly in iTerm2\. diff --git a/package.json b/package.json index 0085c3e..c2a4fea 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ttab", "description": "OSX CLI for opening a new terminal tab/window, optionally with a command to execute and/or display settings", "private": false, - "version": "0.4.0", + "version": "0.5.0", "os": [ "darwin" ], @@ -22,8 +22,11 @@ "test": "make test" }, "keywords": [ + "macos", "osx", "terminal", + "iterm", + "iterm2", "cli", "tabs", "windows", diff --git a/test/opens new tab in front window b/test/00 opens new tab in front window similarity index 100% rename from test/opens new tab in front window rename to test/00 opens new tab in front window diff --git a/test/option -w opens new tab in new window b/test/01 option -w opens new tab in new window similarity index 100% rename from test/option -w opens new tab in new window rename to test/01 option -w opens new tab in new window diff --git a/test/option -d sets working dir b/test/02 option -d sets working dir similarity index 100% rename from test/option -d sets working dir rename to test/02 option -d sets working dir diff --git a/test/new tab inherits working dir b/test/03 new tab inherits working dir similarity index 100% rename from test/new tab inherits working dir rename to test/03 new tab inherits working dir diff --git a/test/script with arguments is executed b/test/04 script with arguments is executed similarity index 100% rename from test/script with arguments is executed rename to test/04 script with arguments is executed diff --git a/test/multiple shell commands are executed b/test/05 multiple shell commands are executed similarity index 95% rename from test/multiple shell commands are executed rename to test/05 multiple shell commands are executed index 60c06a9..5ff7cb6 100755 --- a/test/multiple shell commands are executed +++ b/test/05 multiple shell commands are executed @@ -11,10 +11,10 @@ tell application "Terminal"'s front window set tabCountBefore to count of tabs set thisTab to selected tab - set cmd to "eval 'uname -v >/tmp/_ttab_test_tmpout; :'" + set cmd to "uname -v >/tmp/_ttab_test_tmpout; :" # Create tab - do shell script ttabBin & " " & cmd + do shell script ttabBin & " " & quoted form of cmd if not (count of tabs) > tabCountBefore then error "Failed to create tab in front window." diff --git a/test/option -g does not activate Terminal b/test/06 option -g does not activate Terminal similarity index 98% rename from test/option -g does not activate Terminal rename to test/06 option -g does not activate Terminal index 5a8d445..2a75d1a 100755 --- a/test/option -g does not activate Terminal +++ b/test/06 option -g does not activate Terminal @@ -27,7 +27,7 @@ tell application "Terminal"'s front window if not ok then activate application "Terminal" - error "Terminal unexpectedly stayed the frontmost application." + error "Terminal unexpectedly remained the frontmost application." end if end tell diff --git a/test/option -G does not activate the new tab or window b/test/07 option -G does not activate the new tab or window similarity index 96% rename from test/option -G does not activate the new tab or window rename to test/07 option -G does not activate the new tab or window index d18226f..b2ec92e 100755 --- a/test/option -G does not activate the new tab or window +++ b/test/07 option -G does not activate the new tab or window @@ -18,7 +18,7 @@ tell application "Terminal"'s front window # !! in `(count of tabs)` below. delay 3 - if not (count of tabs) > tabCountBefore then error "Failed to create tab in front window." + if (count of tabs of it) = tabCountBefore then error "Failed to create tab in front window; still-current tab count: " & (count of tabs of it) # Ensure that the original tab is the selected one (again) if not selected of thisTab then diff --git a/test/option -s opens tab with specified settings b/test/08 option -s opens tab with specified settings similarity index 100% rename from test/option -s opens tab with specified settings rename to test/08 option -s opens tab with specified settings diff --git a/test/option -t sets custom title b/test/09 option -t sets custom title similarity index 100% rename from test/option -t sets custom title rename to test/09 option -t sets custom title diff --git a/test/option -a targets a specific terminal application b/test/10 option -a targets a specific terminal application similarity index 74% rename from test/option -a targets a specific terminal application rename to test/10 option -a targets a specific terminal application index 9f26ee8..c240911 100755 --- a/test/option -a targets a specific terminal application +++ b/test/10 option -a targets a specific terminal application @@ -2,7 +2,7 @@ ttabBin="../bin/ttab" -[[ -d /Applications/iTerm.app ]] || { echo "CANNOT TEST OPTION -a, because iTerm2 appears not to be installed." >&2; exit 0; } +[[ -d /Applications/iTerm.app ]] || { echo "WARNING: Cannot test option -a, because iTerm2 appears not to be installed." >&2; exit 0; } numWinsBefore=$(osascript -e 'tell application "iTerm.app" to count windows') diff --git a/test/invalid-syntax shell command should report nonzero exit code b/test/invalid-syntax shell command should report nonzero exit code deleted file mode 100755 index c17f321..0000000 --- a/test/invalid-syntax shell command should report nonzero exit code +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -ttabBin="../bin/ttab" - -# Construct a broken shell command that will cause a syntax error in `ttab` itself. -cmdThatCausesSyntaxError='I am " broken' - -# NOTE: The best `ttab` can do is to create the target tab / window with a *syntactically* -# valid shell command, but it can't meaningfully act on that valid command's runtime failure. -# However, a *syntactically invalid* shell command causes an error in `ttab` itself, -# which it SHOULD reflect in its exit code. - -"$ttabBin" -w "$cmdThatCausesSyntaxError" 2>/dev/null && { echo "Invalid-syntax command '$cmdThatCausesSyntaxError' should have resulted in nonzero exit code, but didn't." >&2; exit 1; } - -exit 0