oNaiPs / dmenu-mac

Dmenu inspired mac port
GNU General Public License v3.0
288 stars 25 forks source link

run command line programs, like nvim or ranger #16

Open despin opened 4 years ago

oNaiPs commented 3 years ago

@despin how would the command line programs run? How could I select the correct terminal to open if so?

despin commented 3 years ago

Anything that is a binary (Programs in $PATH) opened on a terminal window. Perhaps the terminal or its additional parameters can be configurable through a configuration file.

McFrappe commented 3 years ago

@despin how would the command line programs run? How could I select the correct terminal to open if so?

You could maybe use NSWorkspace.shared.openFile(app.path), which opens the file with the default program (in this case, an executable program such as nvim should open with the Terminal).

I forked your repository and gave it a quick go, and by all means, im not familiar with swift as a programming language but was interested if i could get something to work at least.

Link to forked AppListProvider

oNaiPs commented 3 years ago

Hi! Perhaps I can add on preferences an optional list of additional paths to look for. What do you think?

McFrappe commented 3 years ago

Yeah that would be good to do. 👍

McFrappe commented 3 years ago

Do you have any update on this? @oNaiPs

SxC97 commented 3 years ago

I use the following apple script to open terminal apps in new iTerm windows. Perhaps this code could be reworked for dmenu?

on alfred_script(q)
    if application "iTerm2" is running or application "iTerm" is running then
        run script "
            on run {q}
                tell application \"iTerm\"
                    activate
                    try
                        create window with default profile
                        select first window
                    end try
                    tell the first window
                        tell current session to write text q
                    end tell
                end tell
            end run
        " with parameters {q}
    else
        run script "
            on run {q}
                tell application \"iTerm\"
                    activate
                    try
                        create window with default profile
                        select first window
                    end try
                    tell the first window
                        tell current session to write text q
                    end tell
                end tell
            end run
        " with parameters {q}
    end if
end alfred_script

Also, I believe the following command can be used to list all valid terminal commands, functions, and aliases and the options could be passed to dmenu to launch with the apple script above.

compgen -bc

Again, not sure if this would be useful but I thought I would post it because was working on a terminal launcher like rofi for macos before I found this project. I'd love to contribute in any way that I can!

SxC97 commented 3 years ago

Did a little more tinkering and I can get somewhat close to the desired outcome.

compgen -bc | dmenu-mac -p "Launch" | xargs ~/.scripts/.terminal

and the .terminal script is as follows.

#!/usr/bin/env zsh

$q=$1

osascript<<EOF
  on alfred_script(q)
    if application "iTerm" is running or application "iTerm" is running then
      run script "
        on run {q}
          tell application \"iTerm\"
            activate
            try
              create window with default profile
              select first window
            end try
            tell the first window
              tell current session to write text q
            end tell
          end tell
        end run
      " with parameters {q}
    else
      run script "
        on run {q}
          tell application \"iTerm\"
            activate
            try
              create window with default profile
              select first window
            end try
            tell the first window
              tell current session to write text q
            end tell
          end tell
        end run
      " with parameters {q}
    end if
  end alfred_script
EOF

The only problem is that the command does not execute in a new iTerm window, even though this works properly in Alfred. Not sure why but it can probably be blamed on my lack of knowledge of Applescript.

molleweide commented 3 years ago

I just add this because it might be interesting: https://github.com/knazarov/dotfiles/tree/master/bin

Nazarovs launcher and popup makes alacritty into a spotlight search window. Maybe it can add some ideas/inspiration.

tekktonic commented 2 years ago

+1 to this. I just found dmenu-mac trying to find a way to launch acme from plan9ports without wasting a terminal on it and was disappointed to find that the program doesn't actually handle the most common use case for dmenu (dmenu_run)