-
Notifications
You must be signed in to change notification settings - Fork 25
Implements Command Line Matching #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| build | ||
| notes | ||
| *.compiled | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { Mode } from './mode.js' | |
| import Gio from 'gi://Gio' | ||
| import GLib from 'gi://GLib' | ||
| import Mtk from 'gi://Mtk' | ||
| import * as Main from 'resource:///org/gnome/shell/ui/main.js' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems the Main is not used in your code, what's the purpose here? |
||
|
|
||
| export class Action { | ||
|
|
||
|
|
@@ -90,6 +91,28 @@ export class Action { | |
| return global.display.get_tab_list(0, active_workspace) | ||
| } | ||
|
|
||
| get_window_cmdline(window) { | ||
| const pid = window.get_pid(); | ||
|
|
||
| if (!pid) return ""; | ||
|
|
||
| const file = Gio.File.new_for_path(`/proc/${pid}/cmdline`); | ||
| const [ok, contents] = file.load_contents(null); | ||
| if (!ok) return ""; | ||
|
|
||
| try { | ||
| const file = Gio.File.new_for_path(`/proc/${pid}/cmdline`); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines (which might be perfomance-inefficient) are run twice. Is it on purpose? |
||
| const [ok, contents] = file.load_contents(null); | ||
| if (ok && contents) { | ||
| // contents is a ByteArray — decode it manually, replacing nulls with spaces | ||
| return new TextDecoder().decode(contents.map(b => b !== 0 ? b : 32)); | ||
| } | ||
| } catch (e) { | ||
| log(`Error fetching cmdline for pid ${pid}: ${e}`); | ||
| } | ||
|
|
||
| return ""; | ||
| } | ||
|
|
||
| is_conforming(window) { | ||
| const [command, wmNeedle, wmFn, title, titleFn] = [this.command, this.wm_class, this.wmFn, this.title, this.titleFn] | ||
|
|
@@ -99,6 +122,13 @@ export class Action { | |
| const window_title = window.get_title() || '' | ||
|
|
||
| // check if the current window is conforming to the search criteria | ||
| if (this.mode.get(Mode.MATCH_CMDLINE)) { | ||
| const normalize = str => str.trim().replace(/\s+/g, ' '); | ||
| const cmdline = this.get_window_cmdline(window); | ||
| if (!cmdline || !command) return false; | ||
| return normalize(cmdline).endsWith(normalize(command)); | ||
| } | ||
|
|
||
| if (wmNeedle) { // seek by (wm_class_name or wm_class_instance) AND if set, title must match | ||
| if ( | ||
| (window_instance[wmFn](wmNeedle) > -1 || | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What creates the
notesfile? I tend to have the code short, if it is unlikely thenoteswill be created on other machines, I prefer to put such things info .git/info/exclude instead