Skip to content

Commit

Permalink
Merge pull request #42 from kubajaburek/master
Browse files Browse the repository at this point in the history
Hide applications with NoDisplay=true
  • Loading branch information
Biont authored May 11, 2021
2 parents fda862a + 6fd48c0 commit 74ed255
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
8 changes: 6 additions & 2 deletions sway-launcher-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function entries() {
}
BEGINFILE{
application=0;
hidden=0;
block="";
a=0
Expand Down Expand Up @@ -140,12 +141,15 @@ function entries() {
actions[a,"key"]=$0
}
/^Name=/{ (block=="action")? actions[a,"name"]=$2 : name=$2 }
/^NoDisplay=true/{ (block=="action")? actions[a,"hidden"]=1 : hidden=1 }
ENDFILE{
if (application){
print FILENAME "\034desktop\034\033[33m" pre name "\033[0m";
if (!hidden)
print FILENAME "\034desktop\034\033[33m" pre name "\033[0m";
if (a>0)
for (i=1; i<=a; i++)
print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"]
if (!actions[i, "hidden"])
print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"]
}
}' \
$@ </dev/null
Expand Down
19 changes: 19 additions & 0 deletions tests/data/desktop-files/0/applications/nvim.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Desktop Entry]
Version=1.0
Name=Neovim
Type=Application
Terminal=true
Exec=nvim
NoDisplay=true
GenericName=Text Editor

[Desktop Action new-file]
Name=New File
Terminal=true
Exec=nvim

[Desktop Action open-file]
Name=Open File
Terminal=true
NoDisplay=true
Exec=nvim
8 changes: 8 additions & 0 deletions tests/data/desktop-files/0/applications/vim.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Version=1.0
Name=Vim
Type=Application
Terminal=true
Exec=vim
NoDisplay=true
GenericName=Text Editor
12 changes: 10 additions & 2 deletions tests/entries.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@
@test "Wildcard expansion works for extraction of desktop files" {
run ../sway-launcher-desktop.sh entries data/desktop-files/0/applications/*.desktop
[ "$status" -eq 0 ]
[[ ${#lines[@]} == 8 ]]
[[ ${#lines[@]} == 9 ]]
}

@test "Reoccurring desktop file ids are not parsed twice" {
run ../sway-launcher-desktop.sh entries data/desktop-files/**/*.desktop
echo "EXPECTED: foo-bar.desktop ACTUAL: $output"
[ "$status" -eq 0 ]
[[ ${#lines[@]} == 8 ]]
[[ ${#lines[@]} == 9 ]]
}

@test "Hidden desktop entries are ignored" {
run ../sway-launcher-desktop.sh entries data/desktop-files/0/applications/*vim.desktop
[ "$status" -eq 0 ]
[[ ${#lines[@]} == 1 ]]
[[ ${lines[0]} =~ data/desktop-files/0/applications/nvim.desktop ]]
[[ ${lines[0]} =~ ^data/desktop-files/0/applications/nvim.desktop.*Neovim.*(New File).*new-file ]]
}

0 comments on commit 74ed255

Please sign in to comment.