From aec321be32f13f4468716f70f15ad8facb14a446 Mon Sep 17 00:00:00 2001
From: Justin Hileman <justin@justinhileman.info>
Date: Sun, 8 Feb 2015 23:21:41 -0800
Subject: [PATCH] Add tab plugin.

This is a port of a bash function I wrote almost five years ago:

  https://gist.github.com/bobthecow/757788

The fish version is better though ;)

I only have OS X with iTerm and Terminal to test on, but it should be possible to add support for other terminals on other OS. Send a pull request!
---
 plugins/README.md    |  1 +
 plugins/tab/tab.fish | 56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 plugins/tab/tab.fish

diff --git a/plugins/README.md b/plugins/README.md
index 1817ba8..288fa5d 100644
--- a/plugins/README.md
+++ b/plugins/README.md
@@ -36,6 +36,7 @@
 * [__rvm__](https://github.com/bpinto/oh-my-fish/tree/master/plugins/rvm) – [RVM](http://rvm.io) Ruby version manager.
 * [__ssh__](https://github.com/bpinto/oh-my-fish/tree/master/plugins/ssh) – ssh conservative $TERM value helper.
 * [__sublime__](https://github.com/bpinto/oh-my-fish/tree/master/plugins/sublime) – Creates `subl` command line shortcut to launch [Sublime Text editor](http://sublimetext.com/).
+* [__tab__](https://github.com/bpinto/oh-my-fish/tree/master/plugins/tab) – Open the current directory (or any other directory) in a new tab.
 * [__tiny__](https://github.com/bpinto/oh-my-fish/tree/master/plugins/tiny) - tap into github's git.io URL shortener.
 * [__tmux__](https://github.com/bpinto/oh-my-fish/tree/master/plugins/tmux) – Plugin to start tmux with support for 256 colours.
 * [__vi-mode__](https://github.com/bpinto/oh-my-fish/tree/master/plugins/vi-mode) – Basic vi key bindings emulation for fish.
diff --git a/plugins/tab/tab.fish b/plugins/tab/tab.fish
new file mode 100644
index 0000000..b01c5b9
--- /dev/null
+++ b/plugins/tab/tab.fish
@@ -0,0 +1,56 @@
+# Open new iTerm and Terminal tabs from the command line
+#
+# Author: Justin Hileman (http://justinhileman.com)
+#
+# Usage:
+#     tab                   Opens the current directory in a new tab
+#     tab [PATH]            Open PATH in a new tab
+#     tab [CMD]             Open a new tab and execute CMD
+#     tab [PATH] [CMD] ...  You can prolly guess
+
+function tab -d 'Open the current directory (or any other directory) in a new tab'
+  set -l cmd ''
+  set -l cdto $PWD
+
+  if test (count $argv) -gt 0 -a -d $argv[1]
+    pushd . >/dev/null
+    cd $argv[1]
+    set cdto $PWD
+    set -e argv[1]
+    popd >/dev/null
+  end
+
+  if test (count $argv) -gt 0
+    set cmd "; $argv"
+  end
+
+  switch $TERM_PROGRAM
+
+  case 'iTerm.app'
+    osascript 2>/dev/null -e "
+      tell application \"iTerm\"
+        tell current terminal
+          launch session \"Default Session\"
+          tell the last session
+            write text \"cd \\\"$cdto\\\"$cmd\"
+          end tell
+        end tell
+      end tell
+    "
+
+  case 'Apple_Terminal'
+    osascript 2>/dev/null -e "
+      tell application \"Terminal\"
+        activate
+        tell application \"System Events\" to keystroke \"t\" using command down
+        repeat while contents of selected tab of window 1 starts with linefeed
+          delay 0.01
+        end repeat
+        do script \"cd \\\"$cdto\\\"$cmd\" in window 1
+      end tell
+    "
+
+  case '*'
+    echo "Unknown terminal: $TERM_PROGRAM" >&2
+  end
+end
-- 
GitLab