Created
July 17, 2021 11:52
-
-
Save Lessica/dcd7a3beca899a080e5135ce1957772b to your computer and use it in GitHub Desktop.
Make muliple panes in iTerm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
repeatBy() { for i in {1..$(expr $1)}; do echo -n "$2"; done } | |
if [ "$#" -lt 2 ]; then | |
echo "usage: $0 v h [command]" | |
exit 1 | |
fi | |
CMD="$3" | |
VER_CNT=$(expr $1 - 1) | |
VER_SPLIT=$(repeatBy $VER_CNT ' delay 0.3\n keystroke "d" using command down\n') | |
VER_PREV=$(repeatBy $VER_CNT ' delay 0.1\n keystroke "[" using command down\n') | |
HOR_CNT=$(expr $2) | |
HOR_ELEM=" delay 0.3\\\\\\\\n keystroke textToType\\\\\\\\n key code 36\\\\\\\\n" | |
HOR_ELEMS=$(repeatBy $HOR_CNT "\"$HOR_ELEM\"---") | |
HOR_SET=$(echo $HOR_ELEMS | sed "s/\"---\"/ keystroke \"D\" using command down\n/g" | sed "s/\\\\n/\\n/g") | |
HOR_ALL="${HOR_SET: 1:-5}" | |
ALL_CNT=$(expr $1) | |
VER_ELEMS=$(repeatBy $ALL_CNT "\"$HOR_ALL\"---") | |
VER_SET=$(echo $VER_ELEMS | sed "s/\"---\"/\n\n delay 0.3\n keystroke \"]\" using command down\n\n/g" | sed "s/\\\\n/\\n/g") | |
VER_ALL="${VER_SET: 1:-4}" | |
/usr/bin/env osascript <<-EOF | |
tell application "iTerm" | |
activate | |
launch session "Panes" | |
tell application "System Events" | |
tell process "iTerm" | |
set textToType to "$CMD" | |
keystroke "t" using command down | |
$VER_SPLIT | |
$VER_PREV | |
$VER_ALL | |
end tell | |
end tell | |
end tell | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage