You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

100 lines
2.1 KiB

  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. my $tmux_command = "tmux";
  5. my @tmux_set_command = ("set", "-g");
  6. my @tmux_setw_command = ("setw", "-g");
  7. my %color_prefs = (
  8. "arch-aspireone" => "blue,white",
  9. "darwin-mba.local" => "yellow,black",
  10. "newkiwi" => "magenta,white"
  11. );
  12. my $color_def = "green,white";
  13. sub tmux {
  14. my @command = ($tmux_command, );
  15. push(@command, @_);
  16. # print "@command, \n";
  17. system(@command) == 0
  18. or die "system @command failed: $?";
  19. }
  20. sub set {
  21. my @command = @tmux_set_command;
  22. push(@command, @_);
  23. tmux(@command);
  24. }
  25. sub setw {
  26. my @command = @tmux_setw_command;
  27. push(@command, @_);
  28. tmux(@command);
  29. }
  30. sub set_key {
  31. tmux("unbind", "C-b");
  32. set("prefix", "C-z");
  33. tmux("bind-key", "C-z", "send-prefix");
  34. tmux("bind-key", "c", "command-prompt", "new-window '%%'");
  35. }
  36. sub set_prefs {
  37. set("base-index", "1");
  38. set("pane-base-index", "1");
  39. setw("mode-keys", "vi");
  40. set("default-command", "/bin/bash");
  41. set("default-path", $ENV{"HOME"});
  42. set("set-titles", "on");
  43. set("display-panes-time", "5000");
  44. }
  45. sub get_hostname {
  46. my $hostname = $ENV{"HOSTNAME"};
  47. if (! $hostname) {
  48. $hostname = `hostname`;
  49. $hostname =~ s/\n//;
  50. }
  51. return $hostname;
  52. }
  53. sub set_status_line {
  54. my $user = $ENV{"USER"};
  55. my $hostname = get_hostname();
  56. my $tmux_v = `tmux -V`;
  57. $tmux_v =~ s/\n//;
  58. set("status-right", "${user}\@${hostname} | ${tmux_v} ");
  59. }
  60. sub set_colors {
  61. my $hostname = get_hostname();
  62. my $color = $color_prefs{$hostname};
  63. if (! $color) {
  64. $color = $color_def;
  65. }
  66. my ($bg, $fg) = split(/,/, $color);
  67. set("status-bg", $bg);
  68. set("status-fg", $fg);
  69. set("mode-bg", $bg);
  70. set("mode-fg", $fg);
  71. set("pane-active-border-fg", $bg);
  72. set("message-bg", "white");
  73. set("message-fg", "black");
  74. setw("window-status-current-bg", "white");
  75. setw("window-status-current-fg", "black");
  76. setw("window-status-current-attr", "bold");
  77. }
  78. sub main {
  79. set_key();
  80. set_prefs();
  81. set_status_line();
  82. set_colors();
  83. }
  84. main();