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.

tmux.conf.pl 2.0 KiB

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