PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/dmenu_handler.pl

https://gitlab.com/fengshaun/src
Perl | 56 lines | 38 code | 14 blank | 4 comment | 1 complexity | a7964efa27431a511fd6276ce6b54cf1 MD5 | raw file
Possible License(s): MIT, GPL-3.0
  1. #!/usr/bin/perl
  2. use 5.012;
  3. our $browser = "uzbl-browser ";
  4. sub run_dmenu {
  5. my $dmenu = "dmenu -i -p '>' -fn 'Bauhaus:pixelsize=15' -nb '#333333' -nf '#818181' -sb '#1793d1' -sf '#ffffff'";
  6. my @supported_cmds = qw/define search open/;
  7. my $all_cmds = `dmenu_path` . join("\n", @supported_cmds);
  8. my $dmenu_cmd = "echo \"$all_cmds\" | $dmenu";
  9. # this is the returned command
  10. my $cmd = `$dmenu_cmd`;
  11. return 1 if ! $cmd;
  12. # return the command in array form
  13. my @cmd = split / /, $cmd;
  14. }
  15. sub process_output {
  16. my $cmd = shift;
  17. chomp(my @args = @_);
  18. given($cmd) {
  19. when(/define/) { &process_define_cmd(@args) }
  20. when(/search/) { &process_search_cmd(@args) }
  21. when(/open/) { &process_open_cmd(@args) }
  22. default { exec($cmd . join " ", @args) }
  23. }
  24. }
  25. sub process_define_cmd {
  26. #TODO: use the API
  27. my $word = join " ", @_;
  28. exec($browser . "\"http://dictionary.reference.com/browse/$word\"");
  29. }
  30. sub process_search_cmd {
  31. my $query = join "+", @_;
  32. exec($browser . "\"http://duckduckgo.com/?q=$query\"");
  33. }
  34. sub process_open_cmd {
  35. my $url = shift;
  36. given($url) {
  37. when(/^mail$/) { exec("urxvt -e mutt") }
  38. when(/^news$/) { exec("urxvt -e canto") }
  39. when(/^facebook$/) { exec("firefox \"http://facebook.com\"") }
  40. }
  41. }
  42. process_output(run_dmenu);