0

I'm not sure if the title got across what I want to do, but here it is:

I am working on a python project that involves a lot of classes. I use Terminal Vim to do my editing.

As you can Imagine, it is a pain to have to open 10 different terminal tabs, title them and open the correct file in them all manually.

I would like to create a script that uses vim to open up all files in a directory in different tabs within the same window. I would like the script to title the tabs as the name of the file it is opening.

I use the gnome-terminal.

Logically I know how I could do it but I just can't seem to find the commands I need.

It seems like I will be able to do what I wan't with the gnome-terminal command, but I can't seem to get it to work right.

EDIT: vim -p * is helpful, but I would like to find a solution that does exactly what I outlined above. Having each file in its own TERMINAL tab would allow me to Open/Close/temporarily suspend them individually and would generally allow for more convenience.

1

If I understand your question correctly what you want is the -p option. vim -p * will open all the files in the current directory in their own tabs in the same window.

  • Just blew my mind. – Luke Aug 17 '14 at 18:35
  • Happy to help. ;) – WrathOfTux Aug 17 '14 at 18:36
0

After poking around for a bit i was able to do what I wanted with a simple perl script:

I was hung up before because I couldnt get a tab to open in the same window. I now realize that the command is built to create a new instance of a terminal window.

So:

gnome-terminal --tab-with-profile=def 

won't open a new tab like I wanted, but will open a new window (def is the name of my profile)

BUT:

gnome-terminal --tab-with-profile=def --tab-with-profile=def

WILL open 2 tabs in one window(just not my current window, which is fine)

I can give them a title and execute commands to:

gnome-terminal  --tab-with-profile=def --title="foo" -e "vim foobar.txt"

opens a new window(single tab), opens foobar.txt in vim and titles the tab for me

With this in mind, I was able to write the following program:

workTime.txt:

#!/usr/bin/perl
use v5.14;


my $wd = '/home/luke/Pokemon-Battle-Simulator';
chdir($wd);

opendir(DIR,$wd);
my @files = readdir(DIR);

my $cmd = 'gnome-terminal';
my $tab = ' --tab-with-profile=def';
for my $file(@files)
{
    if (($file  ne ".") and ($file ne ".."))
    {
        my $title = '--title=' . $file;
        my $e = "-e 'vim " . $file . "'";
        $cmd .= join(' ', $tab, $title, $e); 
    }
}
print $cmd;

`$cmd`
0

You might want to look at the 'screen' unix tool. It's a terminal "multiplexer" that opens multiple terminals over a single connection (ssh, telnet, or local). It's configurable to automatically open multiple shells or commands (eg. vim, top, etc) in different screens with a new connection. It can also preserve sessions across disconnects, so if you are in the middle of editing a document and your ISP drops out for a few minutes, you can go right back to the edits.

ssh + screen + emacs = win!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.