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.
 
 
 
 
 
 

101 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. # this does not workd because `run' do script asyncly
  38. set("base-index", "1");
  39. set("pane-base-index", "1");
  40. setw("mode-keys", "vi");
  41. set("default-command", "/bin/bash");
  42. set("default-path", $ENV{"HOME"});
  43. set("set-titles", "on");
  44. set("display-panes-time", "5000");
  45. }
  46. sub get_hostname {
  47. my $hostname = $ENV{"HOSTNAME"};
  48. if (! $hostname) {
  49. $hostname = `hostname`;
  50. $hostname =~ s/\n//;
  51. }
  52. return $hostname;
  53. }
  54. sub set_status_line {
  55. my $user = $ENV{"USER"};
  56. my $hostname = get_hostname();
  57. my $tmux_v = `tmux -V`;
  58. $tmux_v =~ s/\n//;
  59. set("status-right", "${user}\@${hostname} | ${tmux_v} ");
  60. }
  61. sub set_colors {
  62. my $hostname = get_hostname();
  63. my $color = $color_prefs{$hostname};
  64. if (! $color) {
  65. $color = $color_def;
  66. }
  67. my ($bg, $fg) = split(/,/, $color);
  68. set("status-bg", $bg);
  69. set("status-fg", $fg);
  70. set("mode-bg", $bg);
  71. set("mode-fg", $fg);
  72. set("pane-active-border-fg", $bg);
  73. set("message-bg", "white");
  74. set("message-fg", "black");
  75. setw("window-status-current-bg", "white");
  76. setw("window-status-current-fg", "black");
  77. setw("window-status-current-attr", "bold");
  78. }
  79. sub main {
  80. set_key();
  81. set_prefs();
  82. set_status_line();
  83. set_colors();
  84. }
  85. main();