Skip to content

Commit

Permalink
Add -w argument to set the working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Jun 11, 2021
1 parent ce66a32 commit f76edc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ gcc -s -O3 -Wall -Wno-deprecated-declarations $(pkg-config --cflags vte-2.91) ke
## Arguments

```
kermit [-h] [-v] [-d] [-c config] [-t title] [-e command]
kermit [-h] [-v] [-d] [-c config] [-t title] [-w workdir] [-e command]
[-h] shows help
[-v] shows version
[-d] enables the debug messages
[-c config] specifies the configuration file
[-t title] sets the terminal title
[-w workdir] sets the working directory
[-e command] sets the command to execute in terminal
```

Expand Down
15 changes: 12 additions & 3 deletions src/kermit.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static char *termTitle; /* Title to set in terminal
static char *wordChars; /* Variables for parsing the config */
static char *fontSize;
static char *configFileName; /* Configuration file name */
static char *workingDir; /* Working directory */
static char *termCommand; /* Command to execute in terminal (-e) */
static char *tabLabelText; /* The label text for showing the tabs situation */
static gchar **envp; /* Variables for starting the terminal */
Expand Down Expand Up @@ -501,10 +502,14 @@ static GtkWidget *getTerm() {
printLog("command: %s %s %s\n", command[0], command[1], command[2]);
}
g_strfreev(envp);
if (workingDir == NULL) {
workingDir = g_get_current_dir();
}
printLog("workdir: %s\n", g_get_current_dir());
/* Spawn terminal asynchronously */
vte_terminal_spawn_async(VTE_TERMINAL(terminal),
VTE_PTY_DEFAULT, /* pty flag */
NULL, /* working directory */
workingDir, /* working directory */
command, /* argv */
NULL, /* environment variables */
G_SPAWN_DEFAULT, /* spawn flag */
Expand Down Expand Up @@ -710,12 +715,16 @@ static void parseSettings() {
* \return 1 on exit
*/
static int parseArgs(int argc, char **argv) {
while ((opt = getopt(argc, argv, ":c:e:t:vdh")) != -1) {
while ((opt = getopt(argc, argv, ":c:w:e:t:vdh")) != -1) {
switch (opt) {
case 'c':
/* Configuration file name to read */
configFileName = optarg;
break;
case 'w':
/* Working directory */
workingDir = optarg;
break;
case 'e':
/* Command to execute in terminal */
termCommand = optarg;
Expand Down Expand Up @@ -746,7 +755,7 @@ static int parseArgs(int argc, char **argv) {
/* Show help message */
fprintf(stderr,
"%s[ %susage%s ] %s [-h] "
"[-v] [-d] [-c config] [-t title] [-e command]%s\n",
"[-v] [-d] [-c config] [-t title] [-w workdir] [-e command]%s\n",
TERM_ATTR_BOLD,
TERM_ATTR_COLOR,
TERM_ATTR_DEFAULT,
Expand Down

0 comments on commit f76edc0

Please sign in to comment.