Skip to content

Commit

Permalink
Auto detect terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper24 committed Feb 4, 2023
1 parent 611e382 commit d24c97a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
1 change: 0 additions & 1 deletion docs/widgets/app_launcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ local app_launcher = bling.widget.app_launcher(args)

```lua
local args = {
terminal = "alacritty" -- Set default terminal
favorites = { "firefox", "wezterm" } -- Favorites are given priority and are bubbled to top of the list
search_commands = true -- Search by app name AND commandline command
skip_names = { "Discord" } -- List of apps to omit from launcher
Expand Down
25 changes: 25 additions & 0 deletions widget/app_launcher/awesome-sensible-terminal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
# Based on i3-sensible-terminal

#
# This code is released in public domain by Han Boetes <[email protected]>
#
# This script tries to exec a terminal emulator by trying some known terminal
# emulators.
#
# We welcome patches that add distribution-specific mechanisms to find the
# preferred terminal emulator. On Debian, there is the x-terminal-emulator
# symlink for example.
#
# Invariants:
# 1. $TERMINAL must come first
# 2. Distribution-specific mechanisms come next, e.g. x-terminal-emulator
# 3. The terminal emulator with best accessibility comes first.
# 4. No order is guaranteed/desired for the remaining terminal emulators.
for terminal in "$TERMINAL" termite hyper wezterm alacritty kitty x-terminal-emulator mate-terminal gnome-terminal terminator xfce4-terminal urxvt rxvt termit Eterm aterm uxterm xterm roxterm lxterminal terminology st qterminal lilyterm tilix terminix konsole guake tilda; do
if command -v "$terminal" > /dev/null 2>&1; then
exec "$terminal" "$@"
fi
done

awesome-client 'local naughty = require("naughty"); naughty.notification { message = "awesome-sensible-terminal could not find a terminal emulator. Please install one." }'
22 changes: 4 additions & 18 deletions widget/app_launcher/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ local path = ...

local app_launcher = { mt = {} }

local terminal_commands_lookup =
{
alacritty = "alacritty -e",
termite = "termite -e",
rxvt = "rxvt -e",
terminator = "terminator -e"
}
local AWESOME_SENSIBLE_TERMINAL_PATH = debug.getinfo(1).source:match("@?(.*/)") ..
"awesome-sensible-terminal"


local function string_levenshtein(str1, str2)
local len1 = string.len(str1)
Expand Down Expand Up @@ -191,16 +187,7 @@ local function create_app_widget(self, entry)

function app.spawn()
if entry.terminal == true then
if self.terminal ~= nil then
local terminal_command = terminal_commands_lookup[self.terminal] or self.terminal
awful.spawn(terminal_command .. " " .. entry.executable)
else
awful.spawn.easy_async("gtk-launch " .. entry.executable, function(stdout, stderr)
if stderr then
awful.spawn(entry.executable)
end
end)
end
awful.spawn.with_shell(AWESOME_SENSIBLE_TERMINAL_PATH .. " -e " .. entry.executable)
else
awful.spawn(entry.executable)
end
Expand Down Expand Up @@ -741,7 +728,6 @@ end
local function new(args)
args = args or {}

args.terminal = args.terminal or nil
args.favorites = args.favorites or {}
args.search_commands = args.search_commands == nil and true or args.search_commands
args.skip_names = args.skip_names or {}
Expand Down

0 comments on commit d24c97a

Please sign in to comment.