Skip to content

Commit

Permalink
Run command with Colon
Browse files Browse the repository at this point in the history
  • Loading branch information
rienovie committed Dec 22, 2024
1 parent 4110554 commit f65790d
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 @@ -493,12 +493,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 @@ -392,6 +392,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 @@ -452,6 +474,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 f65790d

Please sign in to comment.