Skip to content

Commit

Permalink
[Breaking] Don't use -i by default, setting to control it
Browse files Browse the repository at this point in the history
  • Loading branch information
mildsunrise committed Feb 23, 2019
1 parent 1ba2f50 commit 318ef31
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ shell - Change shell used to run commands
resize - Change the terminal size
setsilent - Enable / disable silent output
setlinkpreviews - Enable / disable link expansion
setinteractive - Enable / disable shell interactive flag
help - Get help
file - View and edit small text files
upload - Upload and overwrite raw files
Expand Down
2 changes: 1 addition & 1 deletion lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function Command(reply, context, command) {
this.startTime = Date.now();
this.reply = reply;
this.command = command;
this.pty = pty.spawn(context.shell, ["-ic", command], {
this.pty = pty.spawn(context.shell, [context.interactive ? "-ic" : "-c", command], {
cols: context.size.columns,
rows: context.size.rows,
cwd: context.cwd,
Expand Down
16 changes: 16 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function rootHook(msg, reply, next) {
cwd: defaultCwd,
size: {columns: 40, rows: 20},
silent: true,
interactive: false,
linkPreviews: false,
};

Expand Down Expand Up @@ -286,6 +287,7 @@ bot.command("status", function (msg, reply, next) {
content += "Size: " + context.size.columns + "x" + context.size.rows + "\n";
content += "Directory: " + escapeHtml(context.cwd) + "\n";
content += "Silent: " + (context.silent ? "yes" : "no") + "\n";
content += "Shell interactive: " + (context.interactive ? "yes" : "no") + "\n";
content += "Link previews: " + (context.linkPreviews ? "yes" : "no") + "\n";
var uid = process.getuid(), gid = process.getgid();
if (uid !== gid) uid = uid + "/" + gid;
Expand Down Expand Up @@ -410,6 +412,20 @@ bot.command("setsilent", function (msg, reply, next) {
reply.html("Output will " + (arg ? "" : "not ") + "be sent silently.");
});

// Settings: Interactive
bot.command("setinteractive", function (msg, reply, next) {
var arg = utils.resolveBoolean(msg.args());
if (arg === null)
return reply.html("Use /setinteractive [yes|no] to control whether shell is interactive. Enabling it will cause your aliases in i.e. .bashrc to be honored, but can cause bugs in some shells such as fish.");

if (msg.context.command) {
var command = msg.context.command;
return reply.reply(command.initialMessage.id || msg).html("Can't change the interactive flag while a command is running.");
}
msg.context.interactive = arg;
reply.html("Commands will " + (arg ? "" : "not ") + "be started with interactive shells.");
});

// Settings: Link previews
bot.command("setlinkpreviews", function (msg, reply, next) {
var arg = utils.resolveBoolean(msg.args());
Expand Down

0 comments on commit 318ef31

Please sign in to comment.