summaryrefslogtreecommitdiff
path: root/qtermwidget/ShellCommand.h
blob: 44e0db8ba19930c80fb4c96e1ed75d4baccee15e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
    Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>

    Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/

#ifndef SHELLCOMMAND_H
#define SHELLCOMMAND_H

// Qt
#include <QtCore/QStringList>

namespace Konsole
{

/** 
 * A class to parse and extract information about shell commands. 
 *
 * ShellCommand can be used to:
 *
 * <ul>
 *      <li>Take a command-line (eg "/bin/sh -c /path/to/my/script") and split it
 *          into its component parts (eg. the command "/bin/sh" and the arguments
 *          "-c","/path/to/my/script")
 *      </li>
 *      <li>Take a command and a list of arguments and combine them to 
 *          form a complete command line.
 *      </li>
 *      <li>Determine whether the binary specified by a command exists in the
 *          user's PATH.
 *      </li>
 *      <li>Determine whether a command-line specifies the execution of
 *          another command as the root user using su/sudo etc.
 *      </li>
 * </ul> 
 */
class ShellCommand
{
public:
    /**
     * Constructs a ShellCommand from a command line.
     *
     * @param fullCommand The command line to parse.  
     */
    ShellCommand(const QString& fullCommand);
    /**
     * Constructs a ShellCommand with the specified @p command and @p arguments.
     */
    ShellCommand(const QString& command , const QStringList& arguments);

    /** Returns the command. */
    QString command() const;
    /** Returns the arguments. */
    QStringList arguments() const;

    /** 
     * Returns the full command line. 
     */
    QString fullCommand() const;

    /** Returns true if this is a root command. */
    bool isRootCommand() const;
    /** Returns true if the program specified by @p command() exists. */
    bool isAvailable() const;

    /** Expands environment variables in @p text .*/
    static QString expand(const QString& text);

    /** Expands environment variables in each string in @p list. */
    static QStringList expand(const QStringList& items);

private:
    QStringList _arguments;    
};

}

#endif // SHELLCOMMAND_H