Skip to content

Commit

Permalink
Merge pull request #46 from greymd/feature/bugfix_refactoring
Browse files Browse the repository at this point in the history
Feature/bugfix refactoring
  • Loading branch information
greymd authored May 8, 2017
2 parents 6361211 + 6da6341 commit 22077df
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 42 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ matrix:
env: SH=bash SH_VERSION=3.2 TMUX_VERSION=2.2
- os: linux
env: SH=bash SH_VERSION=3.2 TMUX_VERSION=2.3
- os: linux
env: SH=bash SH_VERSION=3.2 TMUX_VERSION=2.4
- os: linux
env: SH=bash SH_VERSION=4.0 TMUX_VERSION=1.6
- os: linux
Expand All @@ -40,6 +42,8 @@ matrix:
env: SH=bash SH_VERSION=4.0 TMUX_VERSION=2.2
- os: linux
env: SH=bash SH_VERSION=4.0 TMUX_VERSION=2.3
- os: linux
env: SH=bash SH_VERSION=4.0 TMUX_VERSION=2.4
- os: linux
env: SH=bash SH_VERSION=4.1 TMUX_VERSION=1.6
- os: linux
Expand All @@ -58,6 +62,8 @@ matrix:
env: SH=bash SH_VERSION=4.1 TMUX_VERSION=2.2
- os: linux
env: SH=bash SH_VERSION=4.1 TMUX_VERSION=2.3
- os: linux
env: SH=bash SH_VERSION=4.1 TMUX_VERSION=2.4
- os: linux
env: SH=bash SH_VERSION=4.2 TMUX_VERSION=1.6
- os: linux
Expand All @@ -76,6 +82,8 @@ matrix:
env: SH=bash SH_VERSION=4.2 TMUX_VERSION=2.2
- os: linux
env: SH=bash SH_VERSION=4.2 TMUX_VERSION=2.3
- os: linux
env: SH=bash SH_VERSION=4.2 TMUX_VERSION=2.4
- os: linux
env: SH=bash SH_VERSION=4.3 TMUX_VERSION=1.6
- os: linux
Expand All @@ -94,6 +102,8 @@ matrix:
env: SH=bash SH_VERSION=4.3 TMUX_VERSION=2.2
- os: linux
env: SH=bash SH_VERSION=4.3 TMUX_VERSION=2.3
- os: linux
env: SH=bash SH_VERSION=4.3 TMUX_VERSION=2.4
- os: linux
env: SH=bash SH_VERSION=4.4 TMUX_VERSION=1.6
- os: linux
Expand All @@ -112,6 +122,8 @@ matrix:
env: SH=bash SH_VERSION=4.4 TMUX_VERSION=2.2
- os: linux
env: SH=bash SH_VERSION=4.4 TMUX_VERSION=2.3
- os: linux
env: SH=bash SH_VERSION=4.4 TMUX_VERSION=2.4
- os: linux
env: SH=bash SH_VERSION=default TMUX_VERSION=0.8
- os: linux
Expand Down
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<h1 align="center">
<img src="https://raw.githubusercontent.com/wiki/greymd/tmux-xpanes/img/xpanes_logo_1.png" height="206" width="208" />
<h4 align="center">Ultimate terminal divider powered by tmux.</h2>
<h4 align="center">Ultimate terminal divider powered by <a href="https://tmux.github.io/">tmux</a>.</h2>
</h1>
<p align="center">
<a href="https://github.com/greymd/tmux-xpanes/releases/latest"><img src="https://img.shields.io/github/release/greymd/tmux-xpanes.svg" alt="Latest version" /></a>
<a href="https://travis-ci.org/greymd/tmux-xpanes"><img src="https://travis-ci.org/greymd/tmux-xpanes.svg?branch=master" alt="Build Status" /></a>
<a href="LICENSE" alt="MIT License"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" /></a>
<a href="https://tmux.github.io/"><img src="https://img.shields.io/badge/powered_by-tmux-green.svg" alt="tmux" /></a>
</p>
<p align="center">
<img src="https://raw.githubusercontent.com/wiki/greymd/tmux-xpanes/img/movie.gif" alt="Introduction Git Animation" />
Expand All @@ -15,11 +14,11 @@
# Features
* Split tmux's window into multiple panes.
+ Build command lines from given arguments & execute them on the panes.
* Runnable from the terminal without tmux session.
* Runnable within tmux session.
* Runnable from outside of tmux session.
* Runnable from inside of tmux session.
* Operation logging.
* Pane layout arrangement.
* Generate command lines from standard-input (Pipe mode).
* Layout arrangement for panes.
* Generate command lines from standard input (Pipe mode).

# Requirements

Expand Down Expand Up @@ -52,6 +51,7 @@ $ brew install tmux-xpanes
## With Zsh plugin managers

Add this line to `~/.zshrc` in case of [zplug](https://zplug.sh).
Zsh-completion for `xpanes` command is also available. See [Wiki > Installation](https://github.com/greymd/tmux-xpanes/wiki/Installation).

```sh
zplug "greymd/tmux-xpanes"
Expand All @@ -71,7 +71,7 @@ $ sudo install -m 0755 xpanes /usr/local/bin/xpanes

# Usage

Two commands `xpanes` and `tmux-xpanes` are installed. They are same commands (`tmux-xpanes` is alias of `xpanes`). Please use as you like.
Two commands `xpanes` and `tmux-xpanes` will be installed. They are actually same commands (`tmux-xpanes` is alias of `xpanes`). Use one you like.

```
Usage:
Expand Down Expand Up @@ -131,7 +131,7 @@ $ echo 3 │$ echo 4
```

Oh, you are not familiar with key bindings of tmux?
Do not worry. Type `exit` and "Enter" key to close the panes.
Don't worry. Type `exit` and "Enter" key to close the panes.

```
$ exit │$ exit
Expand All @@ -154,14 +154,14 @@ $ exit │$ exit
```

### `-c` option and `-I` option.
`-c` option allow to execute original command line.
`-c` option allows to execute original command line.
For example, try this one.

```sh
$ xpanes -c 'seq {}' 1 2 3 4
```

You will get this screen like this.
You will get the screen like this.

```
$ seq 1 │$ seq 2
Expand Down Expand Up @@ -190,9 +190,9 @@ As you can see, `{}` is replaced each arguments. This placeholder can be changed
$ xpanes -I@ -c 'seq @' 1 2 3 4
```

`echo {}` is used as the default placeholder without `-c` option.
`echo {}` is used as the default placeholder when any commands is not specified by `-c` option.

[Brace expantion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) given by Bash or Zsh is quite useful to generate sequential numbers or alphabetical characters.
[Brace expantion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) given by Bash or Zsh is very useful to generate sequential numbers or alphabetical characters.

```sh
# Same as $ xpanes 1 2 3 4
Expand All @@ -201,28 +201,28 @@ $ xpanes {1..4}

## Behavior modes.

Basic usages are explained as shown above. Before showing applicable usages, it is good to know behavior modes of `xpanes` command.
Basic usages are explained as shown above. Before showing applicable usages, it is good to know about the conditional behavior of `xpanes` command.

### [Normal mode1] Behavior out of the tmux session.

If the tmux is not being opened and `xpanes` command executed on the normal terminal, the command would follow following behavior.
When the tmux is not being opened and `xpanes` command is executed on the normal terminal, the command's behavior is supposed to be...

The command newly creates a tmux session and new window on the session.
In addition, it separates the window into multiple panes. Finally, the session will be attached.

### [Normal mode2] Behavior in the tmux session.

If the tmux is already being opened and `xpanes` command is executed on the tmux, the command's behavior follows follwing.
When the tmux is already being opened and `xpanes` command is executed on the existing tmux session, the command's behavior is supposed to be...

The command newly creates a window **on the exisging active session**.
In addition, it separates the window into multiple panes.
Finally, the window will be active window.

### [Pipe mode] Behavior in the tmux session & Accepting standard input.

If the tmux is already being opened and `xpanes` command is executed on the tmux (same as above).
And, when the command is accepting standard input ( the command followed by any commands and pipe `|`),
the command's follows "Pipe mode". "Pipe mode" will be instructed later.
When the tmux is already being opened and `xpanes` command is executed on the tmux (same as above).
In addition, when the command is accepting standard input ( the command followed by any other commands and pipe `|`),
the command's behavior will be some special one called "Pipe mode". "Pipe mode" will be introduced [later](#pipe-mode).

## Further Examples

Expand Down Expand Up @@ -468,20 +468,20 @@ Pipe mode has two features.

```bash:tmux_session
# The command line generates some numbers.
$ echo "2 4 6 8" | xargs -n 1
$ seq 4
1
2
3
4
6
8
# Add those numbers to xpanes command.
$ echo "2 4 6 8" | xargs -n 1 | xpanes seq
$ seq 4 | xpanes seq
```

The result will be like this.

```
$ seq 2 │$ seq 4
$ seq 1 │$ seq 2
Expand All @@ -492,7 +492,7 @@ $ seq 2 │$ seq 4
------------------------------------------+------------------------------------------
$ seq 6 │$ seq 8
$ seq 3 │$ seq 4
Expand All @@ -507,14 +507,14 @@ $ seq 6 │$ seq 8
Off-course, `-c` and `-I` options are available.

```sh
$ echo "2 4 6 8" | xargs -n 1 | xpanes -c 'seq {}'
$ seq 4 | xpanes -c 'seq {}'
## xpanes seq
## and
## xpanes -c 'seq {}'
## are same.
```

However, giving `-c` and arguments causes error.
However, giving both `-c` and any arguments causes error.

```bash:tmux_session
$ echo test | xpanes -c 'echo {}' echo
Expand Down Expand Up @@ -542,7 +542,7 @@ Host host3
IdentityFile ~/.ssh/id_rsa
```

Parse host name with some UNIX commands.
Parse host name with general UNIX commands.

```sh
$ cat ~/.ssh/config | awk '$1=="Host"{print $2}'
Expand Down Expand Up @@ -583,6 +583,8 @@ $ ssh host3
```

Pipe mode allows you to make combinations between tmux and other UNIX commands like this.

# License

The scripts is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
Expand Down
19 changes: 9 additions & 10 deletions bin/xpanes
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
set -u

# @Author yasuhiro.yamada
# @Author Yamada, Yasuhiro
# @Filename xpanes

set -u
readonly XP_VERSION="2.0.0"

# ===============
Expand Down Expand Up @@ -53,11 +54,10 @@ readonly XP_SESSION_NAME="$XP_THIS_FILE_NAME-$$"
readonly XP_TMP_WIN_NAME="tmp-$$"

readonly XP_SUPPORT_TMUX_VERSION_LOWER="1.6"
readonly XP_SUPPORT_TMUX_VERSION_UPPER="2.3"
readonly XP_SUPPORT_TMUX_VERSIONS="${XP_SUPPORT_TMUX_VERSIONS:-(1.6|1.7|1.8|1.9|1.9a|2.0|2.1|2.2|2.3)}"
readonly XP_SUPPORT_TMUX_VERSION_UPPER="2.4"
readonly XP_SUPPORT_TMUX_VERSIONS="${XP_SUPPORT_TMUX_VERSIONS:-(1.6|1.7|1.8|1.9|1.9a|2.0|2.1|2.2|2.3|2.4)}"
readonly XP_DEPENDENCIES="${XP_DEPENDENCIES:-tmux perl}"


: "Initialize options" && {
# options which work indivisually.
readonly XP_FLAG_OPTIONS="[hVde]"
Expand All @@ -72,8 +72,6 @@ readonly XP_DEPENDENCIES="${XP_DEPENDENCIES:-tmux perl}"
XP_STDIN=()
XP_IS_PIPE_MODE=0
XP_OPT_IS_SYNC=1
XP_KILL_WINDOW_NAME=""
XP_KILL_SESSION_NAME=""
XP_OPT_DRY_RUN=0
XP_OPT_ATTACH=1
XP_OPT_LOG_STORE=0
Expand Down Expand Up @@ -120,7 +118,7 @@ _EOS_
xpns_usage_verbose() {
cat << _EOS_
FORMAT:
Default value is \"$XP_LOG_FORMAT\"
Default value is "$XP_LOG_FORMAT"
Interpreted sequences are:
[:PID:] Process id of the tmux session. (e.g, 41531)
[:ARG:] Argument name
Expand Down Expand Up @@ -602,7 +600,7 @@ xpns_load_arg_options() {
return 0
}

xpns_enable_long_options() {
xpns_load_long_options() {
if [[ "$1" =~ ^--help$ ]]; then
xpns_usage
xpns_usage_verbose
Expand Down Expand Up @@ -675,7 +673,7 @@ xpns_parse_options() {
shift
else
local _shift_count="0"
xpns_enable_long_options "$@"
xpns_load_long_options "$@"
_shift_count="$?"
[ "$_shift_count" = "1" ] && XP_OPTIONS+=("$1") && shift
fi
Expand Down Expand Up @@ -718,6 +716,7 @@ xpns_parse_options() {
# ----------------
*)
XP_ARGS+=("$1")
XP_NO_OPT=1
shift
;;

Expand Down
9 changes: 4 additions & 5 deletions test/matrix.pict
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Let test cases of osx as small as possible because Travis CI takes long time to finish osx's tests.
os:linux(10),osx(1)
os:linux
# Bash -- extract "MAJOR.MINOR" version. Ignore all the patch version's difference.
# Less than version 3.1 is out of support.
shell:bash-default,bash-3.1,bash-3.2,bash-4.0,bash-4.1,bash-4.2,bash-4.3,bash-4.4
tmux:0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.9a,2.0,2.1,2.2,2.3
shell:bash-default,bash-3.2,bash-4.0,bash-4.1,bash-4.2,bash-4.3,bash-4.4
tmux:0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,1.9a,2.0,2.1,2.2,2.3,2.4

IF [os] = "osx" THEN [shell] = "bash-default";
IF [tmux] IN {"0.8","0.9","1.0","1.1","1.2","1.3","1.4","1.5"} THEN [os] = "linux" AND [shell] = "bash-default";
IF NOT [tmux] IN {"0.8","0.9","1.0","1.1","1.2","1.3","1.4","1.5"} THEN [shell] <> "bash-default";

# ============================
# How to generate test cases
Expand Down
43 changes: 43 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,47 @@ tearDown(){

###################### START TESTING ######################

test_no_more_options() {
local _socket_file="${SHUNIT_TMPDIR}/.xpanes-shunit"
local _cmd=""
local _tmpdir="${SHUNIT_TMPDIR}"

_cmd="${EXEC} -I@ -S $_socket_file -c \"cat <<<@ > ${_tmpdir}/@.result\" --stay AA -l ev --help"
printf "\n $ $_cmd\n"
${EXEC} -I@ -S $_socket_file -c "cat <<<@ > ${_tmpdir}/@.result" --stay AA -l ev --help
# hyphen "-" in the window name will be replacet with "_".
wait_panes_separation "$_socket_file" "AA" "4"
wait_all_files_creation ${_tmpdir}/{AA,-l,ev,--help}.result
diff "${_tmpdir}/AA.result" <(cat <<<AA)
assertEquals 0 $?
diff "${_tmpdir}/-l.result" <(cat <<<-l)
assertEquals 0 $?
diff "${_tmpdir}/ev.result" <(cat <<<ev)
assertEquals 0 $?
diff "${_tmpdir}/--help.result" <(cat <<<--help)
assertEquals 0 $?
close_tmux_session "$_socket_file"
rm -f ${_tmpdir}/*.result

: "In TMUX session" && {
printf "\n $ TMUX($_cmd)\n"
create_tmux_session "$_socket_file"
exec_tmux_session "$_socket_file" "$_cmd"
wait_panes_separation "$_socket_file" "AA" "4"
wait_all_files_creation ${_tmpdir}/{AA,-l,ev,--help}.result
diff "${_tmpdir}/AA.result" <(cat <<<AA)
assertEquals 0 $?
diff "${_tmpdir}/-l.result" <(cat <<<-l)
assertEquals 0 $?
diff "${_tmpdir}/ev.result" <(cat <<<ev)
assertEquals 0 $?
diff "${_tmpdir}/--help.result" <(cat <<<--help)
assertEquals 0 $?
close_tmux_session "$_socket_file"
rm -f ${_tmpdir}/*.result
}
}

test_invalid_layout() {
# Option and arguments are continuous.
${EXEC} -lmem 1 2 3
Expand Down Expand Up @@ -928,6 +969,8 @@ test_hyphen_and_option2() {
}
}



test_desync_option_1() {
# If tmux version is less than 1.9, skip this test.
if (is_less_than "1.9");then
Expand Down

0 comments on commit 22077df

Please sign in to comment.