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.
 
 
 
 
 
 

102 lines
2.2 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" => "red,white",
  10. "newkiwi" => "magenta,white"
  11. );
  12. my $color_def = "green,black";
  13. sub tmux {
  14. my @command = ($tmux_command, );
  15. push(@command, @_);
  16. # print "@command, \n";
  17. system(@command) == 0
  18. or warn "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. set("renumber-windows", "on");
  41. setw("mode-keys", "vi");
  42. set("default-command", "/bin/bash");
  43. set("default-path", $ENV{"HOME"});
  44. set("set-titles", "on");
  45. set("display-panes-time", "5000");
  46. }
  47. sub get_hostname {
  48. my $hostname = $ENV{"HOSTNAME"};
  49. if (! $hostname) {
  50. $hostname = `hostname`;
  51. chomp($hostname)
  52. }
  53. return $hostname;
  54. }
  55. sub set_status_line {
  56. my $user = $ENV{"USER"};
  57. my $hostname = get_hostname();
  58. my $tmux_v = `tmux -V`;
  59. $tmux_v =~ s/\n//;
  60. set("status-right", "${user}\@${hostname} | ${tmux_v} ");
  61. }
  62. sub set_colors {
  63. my $hostname = get_hostname();
  64. my $color = $color_prefs{$hostname};
  65. if (! $color) {
  66. $color = $color_def;
  67. }
  68. my ($bg, $fg) = split(/,/, $color);
  69. set("status-bg", $bg);
  70. set("status-fg", $fg);
  71. set("mode-bg", $bg);
  72. set("mode-fg", $fg);
  73. set("pane-active-border-fg", $bg);
  74. set("message-bg", "white");
  75. set("message-fg", "black");
  76. setw("window-status-current-bg", "white");
  77. setw("window-status-current-fg", "black");
  78. #setw("window-status-current-attr", "bold");
  79. }
  80. sub main {
  81. set_key();
  82. set_prefs();
  83. set_status_line();
  84. set_colors();
  85. }
  86. main();