Skip to content

Commit

Permalink
Merge pull request #143 from rienovie/runCommandWithColon
Browse files Browse the repository at this point in the history
Run command with Colon
  • Loading branch information
nwg-piotr authored Jan 20, 2025
2 parents 56aeab3 + f65790d commit 6f8870f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,20 @@ func main() {
} else if key.Keyval() == gdk.KEY_Return {
s := searchEntry.Text()
if s != "" {
// Check if the search box content is an arithmetic expression. If so, display the result
// and copy to the clipboard with wl-copy.
result, e := expr.Eval(s, nil)
if e == nil {
log.Debugf("Setting up mathemathical operation result window. Operation: %s, result: %v", s, result)
setUpOperationResultWindow(s, fmt.Sprintf("%v", result))
// Check if execute command input
if s[0] == ':' {
// Make sure there's something to run
if len(s) > 1 {
launch(substring(s, 1, -1), false, true)
}
} else {
// Check if the search box content is an arithmetic expression. If so, display the result
// and copy to the clipboard with wl-copy.
result, e := expr.Eval(s, nil)
if e == nil {
log.Debugf("Setting up mathemathical operation result window. Operation: %s, result: %v", s, result)
setUpOperationResultWindow(s, fmt.Sprintf("%v", result))
}
}
}
return true
Expand Down
30 changes: 30 additions & 0 deletions uicomponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,28 @@ func setUpSearchEntry() *gtk.SearchEntry {
phrase = sEntry.Text()
if len(phrase) > 0 {

// Check if command input
if phrase[0] == ':' {
// Hide/Destroy everything except "execute command"
if appFlowBox != nil {
appFlowBox.Destroy()
}
if pinnedFlowBox.Visible() {
pinnedFlowBox.Hide()
}
if categoriesWrapper.Visible() {
categoriesWrapper.Hide()
}

if len(phrase) > 1 {
statusLabel.SetText("Execute \"" + substring(phrase, 1, -1) + "\"")
} else {
statusLabel.SetText("Execute a command")
}

return
}

// search apps
appFlowBox = setUpAppsFlowBox(nil, phrase)

Expand Down Expand Up @@ -477,6 +499,14 @@ func setUpSearchEntry() *gtk.SearchEntry {
if fileSearchResultWrapper != nil {
fileSearchResultWrapper.Hide()
}

if !pinnedFlowBox.Visible() {
pinnedFlowBox.ShowAll()
}

if !categoriesWrapper.Visible() {
categoriesWrapper.ShowAll()
}
}
})

Expand Down

0 comments on commit 6f8870f

Please sign in to comment.