Atom Editor Package: open-terminal-here
Modify open-terminal-here for open elementary Terminal(io.elementary.terminal) in the current directory on Atom Editor of Elementary OS (Ubuntu base).

Github usemodj/atom-open-terminal-here: https://github.com/usemodj/atom-open-terminal-here

Open Terminal Here

Open the Terminal (Mac OS X, Linux) or Command Prompt (Windows) in the given directory via context menu or keyboard shortcut.

Ubuntu Linux

  1. Install xdotool:
sudo apt-get install -y xdotool
  1. Download terminal-tab.sh and make it executable:
chmod +x ./terminal-tab.sh
  1. Move the script to a directory in your path:
sudo mv ./terminal-tab.sh /usr/local/bin/terminal-tab

In the open-terminal-here settings,
set Command :
terminal-tab .

sudo vim /usr/local/bin/terminal-tab.sh :

#!/bin/sh
#
# Open a new terminal emulator tab in the current working directory.
#
# Usage:
# ./terminal-tab.sh [-t terminal_emulator] [-w window_name] [-k keystroke]
#
# Requires xdotool:
# http://www.semicomplete.com/projects/xdotool/
#
# Copyright 2015, Sebastian Tschan
# https://blueimp.net
#
# Licensed under the MIT license:
# https://opensource.org/licenses/MIT

# Keyboard shortcut to open a new terminal emulator tab:
KEYSTROKE='ctrl+shift+t'
# Pattern to identify a terminal emulator window by name:
WINDOW_NAME="$USER@$(hostname)"
WINDOW_CLASS="io.elementary.terminal"

# Terminal emulator command:
TERMINAL_EMULATOR='x-terminal-emulator'

# Parse command-line options:
while getopts t:w:k: opt; do
  case $opt in
    t) TERMINAL_EMULATOR="$OPTARG"
       ;;
    w) WINDOW_NAME="$OPTARG"
       ;;
    k) KEYSTROKE="$OPTARG"
       ;;
    ?) echo "Usage: $0 [-t terminal_emulator] [-w window_name] [-k keystroke]"
       exit 2
       ;;
  esac
done

# Search for an open terminal emulator window and bring it into focus:
#xdotool search --limit 1 --name "$WINDOW_NAME" windowactivate
xdotool search --limit 1  --onlyvisible  --class "$WINDOW_CLASS" windowactivate

# echo "KEYSTROKE: $KEYSTROKE"
# Check if xdotool found a matching window:
if [ $? -eq 0 ]; then
# Open a new terminal emulator tab in the current working directory:
#xdotool key "$KEYSTROKE" type --delay 1 "cd '$(pwd | sed "s/'/'\\\''/g")';clear" && xdotool key Return
  xdotool key "$KEYSTROKE" && xdotool sleep 1 && xdotool type --delay 1 --clearmodifiers "cd '$(pwd | sed "s/'/'\\\''/g")';clear" && xdotool key Return
else
  # Open a new terminal emulator window:
  $TERMINAL_EMULATOR
fi

Open a new tab in gnome-terminal using command line

https://stackoverflow.com/questions/1188959/open-a-new-tab-in-gnome-terminal-using-command-line/2164621

sudo vim /usr/local/bin/terminal-tab2.sh :

#!/bin/sh

# This will auto determine the corresponding terminal 
# and opens the tab accordingly.

WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool key ctrl+shift+t $WID

#sleep 1; xdotool type --delay 1 --clearmodifiers "your Command"; xdotool key Return;
xdotool sleep 1; xdotool type --delay 1 --clearmodifiers "cd '$(pwd | sed "s/'/'\\\''/g")';clear"; xdotool key Return;

Leave a Reply