Skip to main content
added 2 characters in body
Source Link
waldyrious
  • 1.6k
  • 17
  • 43

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed --in-place --regexp-extended 's/^(\[[A-Za-z ]+\])$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed s's/<find>/<replace>/<flags><flags>' (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^(\[[A-Za-z ]+\])$ part — RegExr or Regex101 can explain it much better than I could here :))

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed --in-place --regexp-extended 's/^(\[[A-Za-z ]+\])$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed s/<find>/<replace>/<flags> (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^(\[[A-Za-z ]+\])$ part — RegExr or Regex101 can explain it much better than I could here :))

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed --in-place --regexp-extended 's/^(\[[A-Za-z ]+\])$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed 's/<find>/<replace>/<flags>' (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^(\[[A-Za-z ]+\])$ part — RegExr or Regex101 can explain it much better than I could here :))

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

simplify regex in sed command
Source Link
waldyrious
  • 1.6k
  • 17
  • 43

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed --in-place --regexp-extended 's/^\^(\[[A-Za-z ]\+\]\]+\])$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed s/<find>/<replace>/<flags> (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^\^(\[[A-Za-z ]\+\]\]+\])$ part — explanation belowRegExr or Regex101 can explain it much better than I could here :))

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

Note: to understand the regular expression in step 1 of the sed command, you must realize that it includes some escapes that aren't part of regex syntax, but need to be used because you're on a shell. These are \(, \) and \+. Without them, the regex is slighty simpler: ^(\[[A-Za-z ]+\])$. RegExr and Regex101 will explain that, much better than I could here :)

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed --in-place 's/^\(\[[A-Za-z ]\+\]\)$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed s/<find>/<replace>/<flags> (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^\(\[[A-Za-z ]\+\]\)$ part — explanation below)

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

Note: to understand the regular expression in step 1 of the sed command, you must realize that it includes some escapes that aren't part of regex syntax, but need to be used because you're on a shell. These are \(, \) and \+. Without them, the regex is slighty simpler: ^(\[[A-Za-z ]+\])$. RegExr and Regex101 will explain that, much better than I could here :)

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed --in-place --regexp-extended 's/^(\[[A-Za-z ]+\])$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed s/<find>/<replace>/<flags> (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^(\[[A-Za-z ]+\])$ part — RegExr or Regex101 can explain it much better than I could here :))

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

explain one-liner, change -i to the spelled out --in-place, and remove unnecessary -e.
Source Link
waldyrious
  • 1.6k
  • 17
  • 43

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed -ie-in-place 's/^\(\[[A-Za-z ]\{1,\}\]\]\+\]\)$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed s/<find>/<replace>/<flags> (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^\(\[[A-Za-z ]\+\]\)$ part — explanation below)

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

Note: to understand the regular expression in step 1 of the sed command, you must realize that it includes some escapes that aren't part of regex syntax, but need to be used because you're on a shell. These are \(, \) and \+. Without them, the regex is slighty simpler: ^(\[[A-Za-z ]+\])$. RegExr and Regex101 will explain that, much better than I could here :)

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed -ie 's/^\(\[[A-Za-z ]\{1,\}\]\)$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop

Here's a one-liner to fix the issue as described in Gabriel's answer:

cp /usr/share/applications/google-chrome.desktop ~/.local/share/applications && sed --in-place 's/^\(\[[A-Za-z ]\+\]\)$/\1\nStartupWMClass=Google-chrome-stable/g' ~/.local/share/applications/google-chrome.desktop


To unpack and explain this command line a bit: first it copies (cp) the global .desktop file to your user directory, since the latter overrides the former for the current user, and isn't changed by package upgrades.

If that operation succeeds (&&), it then uses the sed command to do a find-replace operation, which follows the pattern sed s/<find>/<replace>/<flags> (where s stands for "substitute"). Step by step, here's what that sed command says:

  1. find all lines that start with [ and end with ] (that's the ^\(\[[A-Za-z ]\+\]\)$ part — explanation below)

  2. replace them with themselves (\1) followed by a newline (\n) and the string "StartupWMClass=Google-chrome-stable"

  3. and do this to all of them, i.e. using the global flag (/g), and directly editing the file (--in-place) rather than outputting to the shell. The last argument is the filename to pass to sed, which is the file the cp command has just created.

Note: to understand the regular expression in step 1 of the sed command, you must realize that it includes some escapes that aren't part of regex syntax, but need to be used because you're on a shell. These are \(, \) and \+. Without them, the regex is slighty simpler: ^(\[[A-Za-z ]+\])$. RegExr and Regex101 will explain that, much better than I could here :)

Source Link
waldyrious
  • 1.6k
  • 17
  • 43
Loading