wmchoose 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/perl -l
  2. =head1 DESCRIPTION
  3. Naive program for B<Window Manager> selection: (over)writes one's
  4. F<`~/.xinitrc'>. Data for the program is appended literally at
  5. the end of it, after the __END__ token and has the form
  6. C<< <key>:<name>:<cmd> >>
  7. where <key> is the key to be selected by the user, preferably
  8. consisting of one or at most a few chars, <name> is the name of
  9. the Window Manager and <cmd> is the command to be put in F<`~/.xinitrc'>.
  10. <key> is case-insensitive and shown uppercase.
  11. In the unlikely event that any item contains literal C<:>'s, any longer
  12. string of colons can be used as a separator instead, like thus:
  13. C<L::LCM:Cool!::exec lcmwm>
  14. Lines with no colons are silently ignored. No additional checking is
  15. performed.
  16. =cut
  17. use strict;
  18. use warnings;
  19. my ($q,%wm,%saw)='Q'; # Quit Key
  20. while (<DATA>) {
  21. chomp;
  22. my $sep;
  23. $sep |= $_ for /:+/g;
  24. $sep or next;
  25. my ($k,$n,$cmd)=split /$sep/;
  26. $k=uc $k;
  27. (warn "$0: Cannot use [$k] as a key for `$n'"),
  28. next if $k eq $q;
  29. (warn "$0: Duplicate key [$k]. Skipping `$n'"),
  30. next if $saw{$k}++;
  31. $wm{$k}=[$n,$cmd];
  32. }
  33. {
  34. print "Choose Window Manager:";
  35. print "[$_] $wm{$_}[0]" for sort keys %wm;
  36. print "[$q] <QUIT>";
  37. chomp(my $in=uc <STDIN>);
  38. last if $in eq $q;
  39. exists $wm{$in} or
  40. (warn "Invalid choice: [$in]\n"), redo;
  41. open my $fh, '>', "$ENV{HOME}/.xinitrc" or
  42. die "Can't write to ~/.xinitrc: $!\n";
  43. print $fh $wm{$in}[1];
  44. print <<"EOT";
  45. `~/.xinitrc' successfully updated for use with $wm{$in}[0]!
  46. Do you want to start X now?
  47. [y/Y] to do so, anything else to quit.
  48. EOT
  49. exec 'startx'
  50. if uc <STDIN> eq "Y\n";
  51. }
  52. __END__
  53. K:KDE:exec startkde
  54. Xm:Xmonad:exec xmonad
  55. X4:XFce4:exec startxfce4
  56. F:Fluxbox:exec fluxbox
  57. L:LXDE:exec startlxde
  58. A:Awesome:exec awesome
  59. I:i3:exec i3