New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting the working directory for commands #941

Closed
bjorn opened this Issue May 12, 2015 · 16 comments

Comments

Projects
None yet
5 participants
@bjorn
Owner

bjorn commented May 12, 2015

It would be nice if the working directory could be specified for the custom commands.

Suggested magic variables:

  • %executablePath - the path of the executable that's supposed to be run
  • %mapPath - the path of the current map file

Originally requested at issue #940.

@bjorn bjorn added the feature label May 12, 2015

@IMMZ

This comment has been minimized.

Show comment
Hide comment
@IMMZ

IMMZ Jun 27, 2015

Contributor

Implementation is on the way.

Questions:

  1. How to get '%executablepath%' if user only specified binary file without full path (for example, 'geany %mapfile')?
  2. Has 'xterm' some parameter to specify working dir? Can't google some...
Contributor

IMMZ commented Jun 27, 2015

Implementation is on the way.

Questions:

  1. How to get '%executablepath%' if user only specified binary file without full path (for example, 'geany %mapfile')?
  2. Has 'xterm' some parameter to specify working dir? Can't google some...
@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jun 27, 2015

Owner

How to get '%executablepath%' if user only specified binary file without full path (for example, 'geany %mapfile')?

One way would be to search the directories in PATH for that executable, but this is tricky and depends on the operating-system. So I'd suggest that in this case, %executablePath is simply an empty string.

Has 'xterm' some parameter to specify working dir? Can't google some...

Why would you need this? You're supposed to set the working directory using QProcess::setWorkingDirectory.

Owner

bjorn commented Jun 27, 2015

How to get '%executablepath%' if user only specified binary file without full path (for example, 'geany %mapfile')?

One way would be to search the directories in PATH for that executable, but this is tricky and depends on the operating-system. So I'd suggest that in this case, %executablePath is simply an empty string.

Has 'xterm' some parameter to specify working dir? Can't google some...

Why would you need this? You're supposed to set the working directory using QProcess::setWorkingDirectory.

@IMMZ

This comment has been minimized.

Show comment
Hide comment
@IMMZ

IMMZ Jun 27, 2015

Contributor

I thought with QProcess::setWorkingDirectory(...) xterm itself runs with working directory, not the process set by user, so it's possible it's not true and I didn't touch 'terminal running' code.

Contributor

IMMZ commented Jun 27, 2015

I thought with QProcess::setWorkingDirectory(...) xterm itself runs with working directory, not the process set by user, so it's possible it's not true and I didn't touch 'terminal running' code.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jun 27, 2015

Owner

I thought with "QProcess::setWorkingDirectory(...)' xterm itself runs with working directory, not the process set by user, so it's possible it's not true and I didn't touch 'terminal running' code.

That might very well be and depends on the behavior of xterm, but it's outside the scope of Tiled to resolve such an issue.

Owner

bjorn commented Jun 27, 2015

I thought with "QProcess::setWorkingDirectory(...)' xterm itself runs with working directory, not the process set by user, so it's possible it's not true and I didn't touch 'terminal running' code.

That might very well be and depends on the behavior of xterm, but it's outside the scope of Tiled to resolve such an issue.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jun 27, 2015

Owner

Hmm, sorry, I just realized there is an "Execute in Terminal" option in the context menu, though it currently only shows up with Qt 4. I'll push a fix to bring it back for Qt 5.

Edit: pushed in change a9292b5

Owner

bjorn commented Jun 27, 2015

Hmm, sorry, I just realized there is an "Execute in Terminal" option in the context menu, though it currently only shows up with Qt 4. I'll push a fix to bring it back for Qt 5.

Edit: pushed in change a9292b5

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jun 27, 2015

Owner

@IMMZ I quickly checked, and the working directory of the process run with xterm -e is matching with the working directory in which xterm was run. Just check for example the output in the window when doing:

cd /tmp
xterm -hold -e pwd

So at least when using xterm, there is no problem here.

Owner

bjorn commented Jun 27, 2015

@IMMZ I quickly checked, and the working directory of the process run with xterm -e is matching with the working directory in which xterm was run. Just check for example the output in the window when doing:

cd /tmp
xterm -hold -e pwd

So at least when using xterm, there is no problem here.

@zcabjro

This comment has been minimized.

Show comment
Hide comment
@zcabjro

zcabjro Aug 31, 2016

Contributor

Any reason this wouldn't work for map path? (command.cpp)

QString Command::finalCommand() const
{
    QString finalCommand = command;

    // Perform variable replacement
    if (MapDocument *mapDocument = DocumentManager::instance()->currentDocument()) {
        const QString fileName = mapDocument->fileName();

        finalCommand.replace(QLatin1String("%mapfile"),
                             QString(QLatin1String("\"%1\"")).arg(fileName));

        QFileInfo fileInfo(fileName);
        QString mapPath = fileInfo.absolutePath();
        finalCommand.replace(
            QLatin1String("%mapPath"),
            QString(QLatin1String("\"%1\"")).arg(mapPath));

        //...
    }

    return finalCommand;
}
Contributor

zcabjro commented Aug 31, 2016

Any reason this wouldn't work for map path? (command.cpp)

QString Command::finalCommand() const
{
    QString finalCommand = command;

    // Perform variable replacement
    if (MapDocument *mapDocument = DocumentManager::instance()->currentDocument()) {
        const QString fileName = mapDocument->fileName();

        finalCommand.replace(QLatin1String("%mapfile"),
                             QString(QLatin1String("\"%1\"")).arg(fileName));

        QFileInfo fileInfo(fileName);
        QString mapPath = fileInfo.absolutePath();
        finalCommand.replace(
            QLatin1String("%mapPath"),
            QString(QLatin1String("\"%1\"")).arg(mapPath));

        //...
    }

    return finalCommand;
}
@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Sep 2, 2016

Owner

@zcabjro That would work for simply adding a %mapPath variable, but this task isn't just about adding that variable but about being able to customize the working directory for the command. @IMMZ tried to implement this, but he eventually closed his pull request (#1004).

Owner

bjorn commented Sep 2, 2016

@zcabjro That would work for simply adding a %mapPath variable, but this task isn't just about adding that variable but about being able to customize the working directory for the command. @IMMZ tried to implement this, but he eventually closed his pull request (#1004).

@zcabjro

This comment has been minimized.

Show comment
Hide comment
@zcabjro

zcabjro Sep 2, 2016

Contributor

Fair enough. I'll open a pull request with this then since it would be useful for running command scripts relative to the map / without absolute paths.

Contributor

zcabjro commented Sep 2, 2016

Fair enough. I'll open a pull request with this then since it would be useful for running command scripts relative to the map / without absolute paths.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Sep 2, 2016

Owner

@zcabjro Sure, looking forward to your pull request! Please keep in mind that the naming for variables has been all lower-case so far, contrary to the names I suggested in this issue, so you should make it %mappath.

Owner

bjorn commented Sep 2, 2016

@zcabjro Sure, looking forward to your pull request! Please keep in mind that the naming for variables has been all lower-case so far, contrary to the names I suggested in this issue, so you should make it %mappath.

@winniehell

This comment has been minimized.

Show comment
Hide comment
@winniehell

winniehell May 16, 2017

A few years passed and I'm having the same problem as in #258 again. 😄 I feel like %executablePath would be a workaround for that situation, so I would be interested in working on it.

@bjorn What is the expected behavior of %executablePath inside of Tiled? I don't feel like a path being relative to the Tiled executable is very helpful. Should it be configurable somewhere?

winniehell commented May 16, 2017

A few years passed and I'm having the same problem as in #258 again. 😄 I feel like %executablePath would be a workaround for that situation, so I would be interested in working on it.

@bjorn What is the expected behavior of %executablePath inside of Tiled? I don't feel like a path being relative to the Tiled executable is very helpful. Should it be configurable somewhere?

@ketanhwr

This comment has been minimized.

Show comment
Hide comment
@ketanhwr

ketanhwr May 17, 2017

Contributor

Hi @winniehell! This particular issue is under my proposal for GSoC '17, so I'll close this one within the next month. You can make any other suggestions here after going through my proposal once: Forum Link

Contributor

ketanhwr commented May 17, 2017

Hi @winniehell! This particular issue is under my proposal for GSoC '17, so I'll close this one within the next month. You can make any other suggestions here after going through my proposal once: Forum Link

@winniehell

This comment has been minimized.

Show comment
Hide comment
@winniehell

winniehell May 17, 2017

@ketanhwr That sounds great, thank you! 👍

winniehell commented May 17, 2017

@ketanhwr That sounds great, thank you! 👍

@ketanhwr

This comment has been minimized.

Show comment
Hide comment
@ketanhwr

ketanhwr May 26, 2017

Contributor

Do you think it's a good idea to make a new column "Arguments" just like Qt Creator? This way, we can easily solve the %executablePath problem too in the working directory. Here's what I have in mind:

workingdir-1

Contributor

ketanhwr commented May 26, 2017

Do you think it's a good idea to make a new column "Arguments" just like Qt Creator? This way, we can easily solve the %executablePath problem too in the working directory. Here's what I have in mind:

workingdir-1

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn May 29, 2017

Owner

@ketanhwr Yes, that's definitely useful. I think I've mentioned it before, since it also solves the problem that using the "Browse" button to choose the executable currently resets the command line arguments.

Owner

bjorn commented May 29, 2017

@ketanhwr Yes, that's definitely useful. I think I've mentioned it before, since it also solves the problem that using the "Browse" button to choose the executable currently resets the command line arguments.

@bjorn

This comment has been minimized.

Show comment
Hide comment
@bjorn

bjorn Jun 3, 2017

Owner

Closed by f59b10c

Owner

bjorn commented Jun 3, 2017

Closed by f59b10c

@bjorn bjorn closed this Jun 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment