Skip to content

Commit

Permalink
Replace echo -ne with printf
Browse files Browse the repository at this point in the history
[echo as defined in POSIX] does not support -e and warns that use of
escape sequences and -n are not portable.  [dash], the default shell in
Debian, includes -ne in its output, which then appears on the first line
of launched terminal applications.  Avoid this by using [printf].

Note: The previous implementation unescaped any printf(3) escape
sequences in Name, rather than only the specified [Desktop Entry string
escape sequences].  The new behavior matches the current behavior for
Exec, where no escape sequences are unescaped.  If unescaping is
desired, it could be added here or in Application::read.

[dash]: https://salsa.debian.org/debian/dash
[echo as defined in POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
[Desktop Entry string escape sequences]: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#value-types
[printf]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

Signed-off-by: Kevin Locke <[email protected]>
  • Loading branch information
kevinoid committed Mar 30, 2020
1 parent af6c001 commit 2e63087
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ApplicationRunner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public:

const std::string command() {
std::string exec = this->application_command();
const std::string &name = this->app.name;
std::stringstream command;

puts(exec.c_str());
Expand All @@ -58,9 +57,13 @@ public:
return std::string();
}

// name with ' escaped for use in single-quoted shell string
std::string nameesc(this->app.name);
replace(nameesc, "'", "'\\''");

fprintf(script, "#!/bin/sh\n");
fprintf(script, "rm %s\n", scriptname);
fprintf(script, "echo -ne \"\\033]2;%s\\007\"\n", name.c_str());
fprintf(script, "printf '\\033]2;%%s\\007' '%s'\n", nameesc.c_str());
fprintf(script, "exec %s", exec.c_str());

//closes also fd
Expand Down

0 comments on commit 2e63087

Please sign in to comment.