From bc577ddef78c4723b90194dd1489c16e63d6d7d4 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Wed, 21 Oct 2020 10:16:17 -0400 Subject: Add more desktop setup --- desktop/.Xresources | 3 +- desktop/.urxvt/ext/clipboard | 115 ++++++++++++++++++++++++++++ desktop/.urxvt/ext/resize-font | 169 +++++++++++++++++++++++++++++++++++++++++ desktop/.xsession | 5 +- old/urxvt/ext/clipboard | 115 ---------------------------- old/urxvt/ext/resize-font | 169 ----------------------------------------- setup.sh | 2 + 7 files changed, 292 insertions(+), 286 deletions(-) create mode 100755 desktop/.urxvt/ext/clipboard create mode 100755 desktop/.urxvt/ext/resize-font delete mode 100755 old/urxvt/ext/clipboard delete mode 100755 old/urxvt/ext/resize-font diff --git a/desktop/.Xresources b/desktop/.Xresources index 9501ece..4bee280 100644 --- a/desktop/.Xresources +++ b/desktop/.Xresources @@ -1,7 +1,8 @@ *customization: -color -urxvt*font: xft:dejavu sans mono:pixelsize=22:antialias=true:hinting=true +!urxvt*font: xft:dejavu sans mono:pixelsize=22:antialias=true:hinting=true !urxvt*font: xft:DejaVu Sans Mono:pixelsize=20:antialias=true:hinting=true ! urxvt*font: xft:fira code:pixelsize=22:antialias=true:hinting=true +urxvt*font: xft:iosevka term:size=14,xft:dejavu sans mono:size=14 !urxvt*letterSpace: -5 !urxvt*font: xft:fira code:pixelsize=22:antialias=true !urxvt*font: xft:inconsolata:size=18:antialias=true diff --git a/desktop/.urxvt/ext/clipboard b/desktop/.urxvt/ext/clipboard new file mode 100755 index 0000000..05e1601 --- /dev/null +++ b/desktop/.urxvt/ext/clipboard @@ -0,0 +1,115 @@ +#! perl -w +# Author: Bert Muennich +# Website: http://www.github.com/muennich/urxvt-perls +# License: GPLv2 + +# Use keyboard shortcuts to copy the selection to the clipboard and to paste +# the clipboard contents (optionally escaping all special characters). +# Requires xsel to be installed! + +# Usage: put the following lines in your .Xdefaults/.Xresources: +# URxvt.perl-ext-common: ...,clipboard +# URxvt.keysym.M-c: perl:clipboard:copy +# URxvt.keysym.M-v: perl:clipboard:paste +# URxvt.keysym.M-C-v: perl:clipboard:paste_escaped + +# Options: +# URxvt.clipboard.autocopy: If true, PRIMARY overwrites clipboard + +# You can also overwrite the system commands to use for copying/pasting. +# The default ones are: +# URxvt.clipboard.copycmd: xsel -ib +# URxvt.clipboard.pastecmd: xsel -ob +# If you prefer xclip, then put these lines in your .Xdefaults/.Xresources: +# URxvt.clipboard.copycmd: xclip -i -selection clipboard +# URxvt.clipboard.pastecmd: xclip -o -selection clipboard +# On Mac OS X, put these lines in your .Xdefaults/.Xresources: +# URxvt.clipboard.copycmd: pbcopy +# URxvt.clipboard.pastecmd: pbpaste + +# The use of the functions should be self-explanatory! + +use strict; + +sub on_start { + my ($self) = @_; + + $self->{copy_cmd} = $self->x_resource('clipboard.copycmd') || 'xsel -ib'; + $self->{paste_cmd} = $self->x_resource('clipboard.pastecmd') || 'xsel -ob'; + + if ($self->x_resource('clipboard.autocopy') eq 'true') { + $self->enable(sel_grab => \&sel_grab); + } + + () +} + +sub copy { + my ($self) = @_; + + if (open(CLIPBOARD, "| $self->{copy_cmd}")) { + my $sel = $self->selection(); + utf8::encode($sel); + print CLIPBOARD $sel; + close(CLIPBOARD); + } else { + print STDERR "error running '$self->{copy_cmd}': $!\n"; + } + + () +} + +sub paste { + my ($self) = @_; + + my $str = `$self->{paste_cmd}`; + if ($? == 0) { + $self->tt_paste($str); + } else { + print STDERR "error running '$self->{paste_cmd}': $!\n"; + } + + () +} + +sub paste_escaped { + my ($self) = @_; + + my $str = `$self->{paste_cmd}`; + if ($? == 0) { + $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g; + $self->tt_paste($str); + } else { + print STDERR "error running '$self->{paste_cmd}': $!\n"; + } + + () +} + +sub on_action { + my ($self, $action) = @_; + + on_user_command($self, "clipboard:" . $action); +} + +sub on_user_command { + my ($self, $cmd) = @_; + + if ($cmd eq "clipboard:copy") { + $self->copy; + } elsif ($cmd eq "clipboard:paste") { + $self->paste; + } elsif ($cmd eq "clipboard:paste_escaped") { + $self->paste_escaped; + } + + () +} + +sub sel_grab { + my ($self) = @_; + + $self->copy; + + () +} diff --git a/desktop/.urxvt/ext/resize-font b/desktop/.urxvt/ext/resize-font new file mode 100755 index 0000000..cc89a96 --- /dev/null +++ b/desktop/.urxvt/ext/resize-font @@ -0,0 +1,169 @@ +# vim:ft=perl:fenc=utf-8 +# Copyright (c) 2009-, Simon Lundström +# Copyright (c) 2014 Maarten de Vries +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# Usage: +# Set your font in ~/.Xresources: +# urxvt.font: xft:Inconsolata:pixelsize=12 +# to set it with pixels or +# urxvt.font: xft:Inconsolata:size=12 +# to set it with points. + +# And re-bind some keymappings (if you want, below are the defaults): +# URxvt.keysym.C-minus: resize-font:smaller +# URxvt.keysym.C-plus: resize-font:bigger +# URxvt.keysym.C-equal: resize-font:reset +# URxvt.keysym.C-question: resize-font:show +# + +my @fonts = ( + {'name' => 'font', 'code' => 710}, + {'name' => 'boldFont', 'code' => 711}, + {'name' => 'italicFont', 'code' => 712}, + {'name' => 'boldItalicFont', 'code' => 713}, +); + +my @fixed = qw(4x6 5x7 5x8 6x9 6x10 6x12 6x13 7x13 7x14 8x13 8x16 9x15 9x18 10x20 12x24); + +sub on_start { + my ($self) = @_; + + foreach (@fonts) { + $_->{'default'} = $self->resource($_->{'name'}); + } +} + +sub on_init { + my ($self) = @_; + my $commands = { + "smaller" => "C-minus", + "bigger" => "C-plus", + "reset" => "C-equal", + "show" => "C-question", + }; + bind_hotkeys($self, $commands); + + () +} + +sub bind_hotkeys { + my ($self, $commands) = @_; + + for (keys %$commands) { + my $hotkey = $$commands{$_}; + my $hotkey_bound = $self->{'term'}->x_resource("keysym.$hotkey"); + if (!defined($hotkey_bound) ) { + # Support old-style key bindings + if ($self->x_resource("%.$_")) { + $hotkey = $self->x_resource("%.$_"); + } + + # FIXME If we're bound to a keysym, don't bind the default. + $self->bind_action($hotkey, "%:$_") or + warn "unable to register '$hotkey' as hotkey for $_"; + } + else { + if ($hotkey_bound !~ /^resize-font:/) { + warn "Hotkey $$commands{$_} already bound to $hotkey_bound, not binding to resize-font:$_ by default."; + } + } + } +} + +sub on_action { + my ($self, $string) = @_; + my $regex = qr"(?!pixelsize=)(\d+)"; + + if ($string eq "bigger") { + foreach (@fonts) { + next if not defined($_->{'default'}); + update_font_size($self, $_, +2); + } + } + elsif ($string eq "smaller") { + foreach (@fonts) { + next if not defined($_->{'default'}); + update_font_size($self, $_, -2); + } + } + elsif ($string eq "reset") { + foreach (@fonts) { + next if not defined($_->{'default'}); + set_font($self, $_, $_->{'default'}); + } + } + elsif ($string eq "show") { + + my $term = $self->{'term'}; + $term->{'resize-font'}{'overlay'} = { + ov => $term->overlay_simple(0, -1, format_font_info($self)), + to => urxvt::timer + ->new + ->start(urxvt::NOW + 1) + ->cb(sub { + delete $term->{'resize-font'}{'overlay'}; + }), + }; + } + + () +} + +sub get_font { + my ($self, $name) = @_; + return $self->resource($name); +} + +sub set_font { + my ($self, $font, $new) = @_; + $self->cmd_parse(sprintf("\33]%d;%s\007", $font->{'code'}, $new)); +} + +sub update_font_size { + my ($self, $font, $delta) = @_; + my $regex = qr"(?<=size=)(\d+)"; + my $current = get_font($self, $font->{'name'}); + + my ($index) = grep { $fixed[$_] eq $current } 0..$#fixed; + if ($index or $index eq 0) { + my $inc = $delta / abs($delta); + $index += $inc; + if ($index < 0) { $index = 0; } + if ($index > $#fixed) { $index = $#fixed; } + $current = $fixed[$index]; + } + else { + $current =~ s/$regex/$1+$delta/ge; + } + set_font($self, $font, $current); +} + +sub format_font_info { + my ($self) = @_; + + my $width = 0; + foreach (@fonts) { + my $length = length($_->{'name'}); + $width = $length > $width ? $length : $width; + } + ++$width; + + my $info = ''; + foreach (@fonts) { + $info .= sprintf("%-${width}s %s\n", $_->{'name'} . ':', get_font($self, $_->{'name'})); + } + + return $info; +} diff --git a/desktop/.xsession b/desktop/.xsession index 6d76b30..102d280 100755 --- a/desktop/.xsession +++ b/desktop/.xsession @@ -18,6 +18,9 @@ xset -b trayer --edge top --align right --SetDockType true --SetPartialStrut true --expand true --width 100 --widthtype pixel --transparent true --alpha 0 --tint 0x000000 --height 18 & [[ -f /etc/nixos/configuration.nix ]] || \ redshift -l 40:-70 -r -t 5500:3700 & -exec xmonad +if which autorandr >/dev/null; then + autorandr --change +fi +exec xmonad diff --git a/old/urxvt/ext/clipboard b/old/urxvt/ext/clipboard deleted file mode 100755 index 05e1601..0000000 --- a/old/urxvt/ext/clipboard +++ /dev/null @@ -1,115 +0,0 @@ -#! perl -w -# Author: Bert Muennich -# Website: http://www.github.com/muennich/urxvt-perls -# License: GPLv2 - -# Use keyboard shortcuts to copy the selection to the clipboard and to paste -# the clipboard contents (optionally escaping all special characters). -# Requires xsel to be installed! - -# Usage: put the following lines in your .Xdefaults/.Xresources: -# URxvt.perl-ext-common: ...,clipboard -# URxvt.keysym.M-c: perl:clipboard:copy -# URxvt.keysym.M-v: perl:clipboard:paste -# URxvt.keysym.M-C-v: perl:clipboard:paste_escaped - -# Options: -# URxvt.clipboard.autocopy: If true, PRIMARY overwrites clipboard - -# You can also overwrite the system commands to use for copying/pasting. -# The default ones are: -# URxvt.clipboard.copycmd: xsel -ib -# URxvt.clipboard.pastecmd: xsel -ob -# If you prefer xclip, then put these lines in your .Xdefaults/.Xresources: -# URxvt.clipboard.copycmd: xclip -i -selection clipboard -# URxvt.clipboard.pastecmd: xclip -o -selection clipboard -# On Mac OS X, put these lines in your .Xdefaults/.Xresources: -# URxvt.clipboard.copycmd: pbcopy -# URxvt.clipboard.pastecmd: pbpaste - -# The use of the functions should be self-explanatory! - -use strict; - -sub on_start { - my ($self) = @_; - - $self->{copy_cmd} = $self->x_resource('clipboard.copycmd') || 'xsel -ib'; - $self->{paste_cmd} = $self->x_resource('clipboard.pastecmd') || 'xsel -ob'; - - if ($self->x_resource('clipboard.autocopy') eq 'true') { - $self->enable(sel_grab => \&sel_grab); - } - - () -} - -sub copy { - my ($self) = @_; - - if (open(CLIPBOARD, "| $self->{copy_cmd}")) { - my $sel = $self->selection(); - utf8::encode($sel); - print CLIPBOARD $sel; - close(CLIPBOARD); - } else { - print STDERR "error running '$self->{copy_cmd}': $!\n"; - } - - () -} - -sub paste { - my ($self) = @_; - - my $str = `$self->{paste_cmd}`; - if ($? == 0) { - $self->tt_paste($str); - } else { - print STDERR "error running '$self->{paste_cmd}': $!\n"; - } - - () -} - -sub paste_escaped { - my ($self) = @_; - - my $str = `$self->{paste_cmd}`; - if ($? == 0) { - $str =~ s/([!#\$%&\*\(\) ='"\\\|\[\]`~,<>\?])/\\\1/g; - $self->tt_paste($str); - } else { - print STDERR "error running '$self->{paste_cmd}': $!\n"; - } - - () -} - -sub on_action { - my ($self, $action) = @_; - - on_user_command($self, "clipboard:" . $action); -} - -sub on_user_command { - my ($self, $cmd) = @_; - - if ($cmd eq "clipboard:copy") { - $self->copy; - } elsif ($cmd eq "clipboard:paste") { - $self->paste; - } elsif ($cmd eq "clipboard:paste_escaped") { - $self->paste_escaped; - } - - () -} - -sub sel_grab { - my ($self) = @_; - - $self->copy; - - () -} diff --git a/old/urxvt/ext/resize-font b/old/urxvt/ext/resize-font deleted file mode 100755 index cc89a96..0000000 --- a/old/urxvt/ext/resize-font +++ /dev/null @@ -1,169 +0,0 @@ -# vim:ft=perl:fenc=utf-8 -# Copyright (c) 2009-, Simon Lundström -# Copyright (c) 2014 Maarten de Vries -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -# Usage: -# Set your font in ~/.Xresources: -# urxvt.font: xft:Inconsolata:pixelsize=12 -# to set it with pixels or -# urxvt.font: xft:Inconsolata:size=12 -# to set it with points. - -# And re-bind some keymappings (if you want, below are the defaults): -# URxvt.keysym.C-minus: resize-font:smaller -# URxvt.keysym.C-plus: resize-font:bigger -# URxvt.keysym.C-equal: resize-font:reset -# URxvt.keysym.C-question: resize-font:show -# - -my @fonts = ( - {'name' => 'font', 'code' => 710}, - {'name' => 'boldFont', 'code' => 711}, - {'name' => 'italicFont', 'code' => 712}, - {'name' => 'boldItalicFont', 'code' => 713}, -); - -my @fixed = qw(4x6 5x7 5x8 6x9 6x10 6x12 6x13 7x13 7x14 8x13 8x16 9x15 9x18 10x20 12x24); - -sub on_start { - my ($self) = @_; - - foreach (@fonts) { - $_->{'default'} = $self->resource($_->{'name'}); - } -} - -sub on_init { - my ($self) = @_; - my $commands = { - "smaller" => "C-minus", - "bigger" => "C-plus", - "reset" => "C-equal", - "show" => "C-question", - }; - bind_hotkeys($self, $commands); - - () -} - -sub bind_hotkeys { - my ($self, $commands) = @_; - - for (keys %$commands) { - my $hotkey = $$commands{$_}; - my $hotkey_bound = $self->{'term'}->x_resource("keysym.$hotkey"); - if (!defined($hotkey_bound) ) { - # Support old-style key bindings - if ($self->x_resource("%.$_")) { - $hotkey = $self->x_resource("%.$_"); - } - - # FIXME If we're bound to a keysym, don't bind the default. - $self->bind_action($hotkey, "%:$_") or - warn "unable to register '$hotkey' as hotkey for $_"; - } - else { - if ($hotkey_bound !~ /^resize-font:/) { - warn "Hotkey $$commands{$_} already bound to $hotkey_bound, not binding to resize-font:$_ by default."; - } - } - } -} - -sub on_action { - my ($self, $string) = @_; - my $regex = qr"(?!pixelsize=)(\d+)"; - - if ($string eq "bigger") { - foreach (@fonts) { - next if not defined($_->{'default'}); - update_font_size($self, $_, +2); - } - } - elsif ($string eq "smaller") { - foreach (@fonts) { - next if not defined($_->{'default'}); - update_font_size($self, $_, -2); - } - } - elsif ($string eq "reset") { - foreach (@fonts) { - next if not defined($_->{'default'}); - set_font($self, $_, $_->{'default'}); - } - } - elsif ($string eq "show") { - - my $term = $self->{'term'}; - $term->{'resize-font'}{'overlay'} = { - ov => $term->overlay_simple(0, -1, format_font_info($self)), - to => urxvt::timer - ->new - ->start(urxvt::NOW + 1) - ->cb(sub { - delete $term->{'resize-font'}{'overlay'}; - }), - }; - } - - () -} - -sub get_font { - my ($self, $name) = @_; - return $self->resource($name); -} - -sub set_font { - my ($self, $font, $new) = @_; - $self->cmd_parse(sprintf("\33]%d;%s\007", $font->{'code'}, $new)); -} - -sub update_font_size { - my ($self, $font, $delta) = @_; - my $regex = qr"(?<=size=)(\d+)"; - my $current = get_font($self, $font->{'name'}); - - my ($index) = grep { $fixed[$_] eq $current } 0..$#fixed; - if ($index or $index eq 0) { - my $inc = $delta / abs($delta); - $index += $inc; - if ($index < 0) { $index = 0; } - if ($index > $#fixed) { $index = $#fixed; } - $current = $fixed[$index]; - } - else { - $current =~ s/$regex/$1+$delta/ge; - } - set_font($self, $font, $current); -} - -sub format_font_info { - my ($self) = @_; - - my $width = 0; - foreach (@fonts) { - my $length = length($_->{'name'}); - $width = $length > $width ? $length : $width; - } - ++$width; - - my $info = ''; - foreach (@fonts) { - $info .= sprintf("%-${width}s %s\n", $_->{'name'} . ':', get_font($self, $_->{'name'})); - } - - return $info; -} diff --git a/setup.sh b/setup.sh index e1a42db..ba40f6c 100755 --- a/setup.sh +++ b/setup.sh @@ -4,6 +4,8 @@ set -euo pipefail STOW="stow -R --no-folding -v" cd "$(dirname $0)" +git submodule update --init --recursive + $STOW common $STOW zsh source $HOME/.zshenv -- cgit v1.2.3