Sway organisation

This commit is contained in:
Charlotte Van Petegem 2020-02-21 15:06:02 +01:00
parent f23200c460
commit ec5adf3828
4 changed files with 211 additions and 187 deletions

View file

@ -0,0 +1,9 @@
{ pkgs }:
pkgs.writeScriptBin "color_picker" ''
#!${pkgs.zsh}/bin/zsh
color=$(${pkgs.grim}/bin/grim -t png -g "$(${pkgs.slurp}/bin/slurp -p)" - | ${pkgs.imagemagick}/bin/convert png:- -unique-colors txt:- | grep -o '#[A-F0-9]\+')
${pkgs.sway}/bin/swaymsg exec -- "echo -n '$color' | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
''

View file

@ -2,187 +2,9 @@ with import <nixpkgs> {};
{ pkgs, ... }:
let
gemoji = pkgs.buildRubyGem {
pname = "gemoji";
gemName = "gemoji";
source.sha256 = "1xv38sxql1fmaxi5lzj6v98l2aqhi6bqkhi6kqd0k38vw40l3yqc";
type = "gem";
version = "4.0.0.rc2";
};
emoji_list = stdenv.mkDerivation {
name = "emoji_list";
buildInputs = [ pkgs.ruby gemoji ];
unpackPhase = "true";
buildPhase = ''
cat > extract_emoji.rb <<HERE
require 'emoji'
File.open('emoji_list.txt', 'w') do |f|
Emoji.all.each do |e|
f.puts("#{e.raw} #{e.description} #{e.name}#{(" " + e.tags.join(" ")) if e.tags.any?} (#{e.category})")
end
end
HERE
ruby extract_emoji.rb
'';
installPhase = ''
cp emoji_list.txt $out
'';
};
launcher = pkgs.writeScript "launcher" ''
#!${pkgs.zsh}/bin/zsh
_sighandler() {
kill -INT "$child" 2>/dev/null
}
calc_options() {
echo "calc "
}
calc() {
if [ -n "$1" ]
then
${pkgs.libqalculate}/bin/qalc "$1"
sleep 5
else
${pkgs.libqalculate}/bin/qalc
fi
}
emoji_options() {
cat ${emoji_list} | sed "s/^/emoji /"
}
emoji() {
char=$(echo -n "$1" | sed "s/^\([^ ]*\) .*/\1/")
${pkgs.sway}/bin/swaymsg exec -- "echo -n $char | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
}
record_options() {
${pkgs.sway}/bin/swaymsg -t get_outputs | ${pkgs.jq}/bin/jq -r '.[]["name"]' | sed "s/^/record /"
echo record select
}
record() {
filename="$(${xdg-user-dirs}/bin/xdg-user-dir VIDEOS)/$(date +'screenrecording_%y-%m-%d-%H%M%S.mp4')"
trap _sighandler SIGINT
if [[ "$1" = "select" ]]
then
${pkgs.wf-recorder}/bin/wf-recorder -g "$(${pkgs.slurp}/bin/slurp)" -f "$filename" &
else
wf-recorder -o $! -f "$filename" &
fi
child=$!
wait "$child"
# We wait two times, because the first wait exits when the process receives a signal. The process might have finished though, so we ignore errors.
wait "$child" 2>/dev/null
if [ -f "$filename" ]
then
echo "Saved as $filename"
else
echo "Something went wrong while recording"
fi
sleep 5
}
run_options() {
print -rl -- ''${(ko)commands} | sed "s/^/run /"
}
run() {
${pkgs.sway}/bin/swaymsg exec $1
}
ssh_options() {
cat $HOME/.ssh/config | grep "^Host [a-zA-Z]\+" | sed "s/Host /ssh /"
}
ssh() {
${pkgs.sway}/bin/swaymsg exec "${pkgs.kitty}/bin/kitty -e ssh $1"
}
systemctl_options() {
echo systemctl hibernate
echo systemctl poweroff
echo systemctl reboot
echo systemctl suspend
}
tmuxinator_options() {
ls ~/.config/tmuxinator | sed "s/\.yml$//" | sed "s/^/tmuxinator /"
}
tmuxinator() {
${pkgs.sway}/bin/swaymsg exec "${pkgs.kitty}/bin/kitty -e ${pkgs.tmuxinator}/bin/tmuxinator start $1"
}
windows_options() {
${pkgs.sway}/bin/swaymsg -t get_tree | ${pkgs.jq}/bin/jq -r 'recurse(.nodes[]?)|recurse(.floating_nodes[]?)|select(.layout=="none")|select(.app_id!="launcher")|select(.type=="con"),select(.type=="floating_con")|(if .app_id then .app_id else .window_properties.class end)+": "+.name+" ("+(.id|tostring)+")"' | sed "s/^/windows /"
}
windows() {
window=$(echo $@ | sed 's/.* (\([^)]*\))$/\1/')
${pkgs.sway}/bin/swaymsg \[con_id="$window"\] focus
}
CHOSEN=$(cat <(windows_options) <(tmuxinator_options) <(ssh_options) <(systemctl_options) <(run_options) <(record_options) <(calc_options) <(emoji_options) | ${pkgs.fzy}/bin/fzy --lines 36 | tail -n1)
if [ -n "$CHOSEN" ]
then
PREFIX=$(echo $CHOSEN | sed "s/^\([^ ]*\) .*/\1/g")
WORD=$(echo $CHOSEN | sed "s/^[^ ]* \(.*\)/\1/g")
$PREFIX $WORD
fi
'';
color-picker = pkgs.writeScriptBin "color_picker" ''
#!${pkgs.zsh}/bin/zsh
color=$(${pkgs.grim}/bin/grim -t png -g "$(${pkgs.slurp}/bin/slurp -p)" - | ${pkgs.imagemagick}/bin/convert png:- -unique-colors txt:- | grep -o '#[A-F0-9]\+')
${pkgs.sway}/bin/swaymsg exec -- "echo -n '$color' | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
'';
screenshot = pkgs.writeScript "screenshot" ''
#!${pkgs.zsh}/bin/zsh
while getopts ":rd" opt
do
case "''${opt}" in
r)
remote=true
;;
d)
delay=true
;;
esac
done
dims="$(${pkgs.slurp}/bin/slurp)"
if [[ -n "$delay" ]]
then
sleep 5
fi
if [[ -n "$remote" ]]
then
name=$(${pkgs.utillinux}/bin/uuidgen).png
${pkgs.grim}/bin/grim -t png -g "$dims" - | ${pkgs.openssh}/bin/ssh sunspear "cat > /usr/share/nginx/html/screenshots/$name"
path="https://cvpetegem.be/screenshots/$name"
else
name=$(date +'screenshot_%Y-%m-%d-%H%M%S.png')
path="$(${pkgs.xdg-user-dirs}/bin/xdg-user-dir PICTURES)/$name"
${pkgs.grim}/bin/grim -g "$dims" "$path"
fi
${pkgs.sway}/bin/swaymsg exec -- "echo -n '$path' | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
${pkgs.libnotify}/bin/notify-send "Screenshot taken" "$path"
'';
launcher = import ./launcher.nix { inherit pkgs stdenv; };
color-picker = import ./color-picker.nix { inherit pkgs; };
screenshot = import ./screenshot.nix { inherit pkgs; };
in
{
imports = [
@ -207,7 +29,7 @@ in
};
home-manager.users.charlotte = { pkgs, ... }: {
home.packages = [ color-picker ];
home.packages = [ color-picker launcher screenshot ];
xdg.configFile."sway/config".text = ''
# Config for sway
#
@ -226,7 +48,7 @@ in
set $term ${pkgs.kitty}/bin/kitty
# Your preferred application launcher
# Note: it's recommended that you pass the final command to sway
set $menu $term --class launcher -e ${launcher}
set $menu $term --class launcher -e ${launcher}/bin/launcher
### Output configuration
exec_always pkill kanshi; exec ${pkgs.kanshi}/bin/kanshi
@ -270,6 +92,9 @@ in
# Launcher popup
for_window [app_id="launcher"] floating enable
# Start accentor as floating window
for_window [class="accentor.Main"] floating enable
### Startup programs
#
exec ${pkgs.firefox}/bin/firefox
@ -296,12 +121,25 @@ in
xkb_numlock enabled
}
input "3141:30354:SONiX_USB_Keyboard" {
xkb_layout "us"
xkb_variant "altgr-intl"
xkb_numlock enabled
}
input "1241:513:USB-HID_Keyboard" {
xkb_layout "us"
xkb_variant "altgr-intl"
xkb_numlock enabled
}
input "1102:4639:DELL081C:00_044E:121F_Touchpad" {
drag enabled
dwt enabled
scroll_method two_finger
tap enabled
}
input "2:7:SynPS/2_Synaptics_TouchPad" {
drag enabled
dwt enabled
@ -339,10 +177,10 @@ in
bindsym $mod+c exec ${pkgs.swaylock}/bin/swaylock -f -c 000000
# screenshot
bindsym Print exec ${screenshot}
bindsym Alt+Print exec ${screenshot} -d
bindsym Shift+Print exec ${screenshot} -r
bindsym Alt+Shift+Print exec ${screenshot} -r -d
bindsym Print exec ${screenshot}/bin/screenshot
bindsym Alt+Print exec ${screenshot}/bin/screenshot -d
bindsym Shift+Print exec ${screenshot}/bin/screenshot -r
bindsym Alt+Shift+Print exec ${screenshot}/bin/screenshot -r -d
# audio
bindsym XF86AudioRaiseVolume exec ${pkgs.pulseaudio}/bin/pactl set-sink-volume $(${pkgs.pulseaudio}/bin/pacmd list-sinks |${pkgs.gawk}/bin/awk '/* index:/{print $3}') +5%

139
programs/sway/launcher.nix Normal file
View file

@ -0,0 +1,139 @@
{ pkgs, stdenv }:
let
gemoji = pkgs.buildRubyGem {
pname = "gemoji";
gemName = "gemoji";
source.sha256 = "1xv38sxql1fmaxi5lzj6v98l2aqhi6bqkhi6kqd0k38vw40l3yqc";
type = "gem";
version = "4.0.0.rc2";
};
emoji_list = stdenv.mkDerivation {
name = "emoji_list";
buildInputs = [ pkgs.ruby gemoji ];
unpackPhase = "true";
buildPhase = ''
cat > extract_emoji.rb <<HERE
require 'emoji'
File.open('emoji_list.txt', 'w') do |f|
Emoji.all.each do |e|
f.puts("#{e.raw} #{e.description} #{e.name}#{(" " + e.tags.join(" ")) if e.tags.any?} (#{e.category})")
end
end
HERE
ruby extract_emoji.rb
'';
installPhase = ''
cp emoji_list.txt $out
'';
};
in
pkgs.writeScriptBin "launcher" ''
#!${pkgs.zsh}/bin/zsh
_sighandler() {
kill -INT "$child" 2>/dev/null
}
calc_options() {
echo "calc "
}
calc() {
if [ -n "$1" ]
then
${pkgs.libqalculate}/bin/qalc "$1"
sleep 5
else
${pkgs.libqalculate}/bin/qalc
fi
}
emoji_options() {
cat ${emoji_list} | sed "s/^/emoji /"
}
emoji() {
char=$(echo -n "$1" | sed "s/^\([^ ]*\) .*/\1/")
${pkgs.sway}/bin/swaymsg exec -- "echo -n $char | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
}
record_options() {
${pkgs.sway}/bin/swaymsg -t get_outputs | ${pkgs.jq}/bin/jq -r '.[]["name"]' | sed "s/^/record /"
echo record select
}
record() {
filename="$(${pkgs.xdg-user-dirs}/bin/xdg-user-dir VIDEOS)/$(date +'screenrecording_%y-%m-%d-%H%M%S.mp4')"
trap _sighandler SIGINT
if [[ "$1" = "select" ]]
then
${pkgs.wf-recorder}/bin/wf-recorder -g "$(${pkgs.slurp}/bin/slurp)" -f "$filename" &
else
wf-recorder -o $! -f "$filename" &
fi
child=$!
wait "$child"
# We wait two times, because the first wait exits when the process receives a signal. The process might have finished though, so we ignore errors.
wait "$child" 2>/dev/null
if [ -f "$filename" ]
then
echo "Saved as $filename"
else
echo "Something went wrong while recording"
fi
sleep 5
}
run_options() {
print -rl -- ''${(ko)commands} | sed "s/^/run /"
}
run() {
${pkgs.sway}/bin/swaymsg exec $1
}
ssh_options() {
cat $HOME/.ssh/config | grep "^Host [a-zA-Z]\+" | sed "s/Host /ssh /"
}
ssh() {
${pkgs.sway}/bin/swaymsg exec "${pkgs.kitty}/bin/kitty -e ssh $1"
}
systemctl_options() {
echo systemctl hibernate
echo systemctl poweroff
echo systemctl reboot
echo systemctl suspend
}
tmuxinator_options() {
ls ~/.config/tmuxinator | sed "s/\.yml$//" | sed "s/^/tmuxinator /"
}
tmuxinator() {
${pkgs.sway}/bin/swaymsg exec "${pkgs.kitty}/bin/kitty -e ${pkgs.tmuxinator}/bin/tmuxinator start $1"
}
windows_options() {
${pkgs.sway}/bin/swaymsg -t get_tree | ${pkgs.jq}/bin/jq -r 'recurse(.nodes[]?)|recurse(.floating_nodes[]?)|select(.layout=="none")|select(.app_id!="launcher")|select(.type=="con"),select(.type=="floating_con")|(if .app_id then .app_id else .window_properties.class end)+": "+.name+" ("+(.id|tostring)+")"' | sed "s/^/windows /"
}
windows() {
window=$(echo $@ | sed 's/.* (\([^)]*\))$/\1/')
${pkgs.sway}/bin/swaymsg \[con_id="$window"\] focus
}
CHOSEN=$(cat <(windows_options) <(tmuxinator_options) <(ssh_options) <(systemctl_options) <(run_options) <(record_options) <(calc_options) <(emoji_options) | ${pkgs.fzy}/bin/fzy --lines 36 | tail -n1)
if [ -n "$CHOSEN" ]
then
PREFIX=$(echo $CHOSEN | sed "s/^\([^ ]*\) .*/\1/g")
WORD=$(echo $CHOSEN | sed "s/^[^ ]* \(.*\)/\1/g")
$PREFIX $WORD
fi
''

View file

@ -0,0 +1,38 @@
{ pkgs }:
pkgs.writeScriptBin "screenshot" ''
#!${pkgs.zsh}/bin/zsh
while getopts ":rd" opt
do
case "''${opt}" in
r)
remote=true
;;
d)
delay=true
;;
esac
done
dims="$(${pkgs.slurp}/bin/slurp)"
if [[ -n "$delay" ]]
then
sleep 5
fi
if [[ -n "$remote" ]]
then
name=$(${pkgs.utillinux}/bin/uuidgen).png
${pkgs.grim}/bin/grim -t png -g "$dims" - | ${pkgs.openssh}/bin/ssh sunspear "cat > /usr/share/nginx/html/screenshots/$name"
path="https://cvpetegem.be/screenshots/$name"
else
name=$(date +'screenshot_%Y-%m-%d-%H%M%S.png')
path="$(${pkgs.xdg-user-dirs}/bin/xdg-user-dir PICTURES)/$name"
${pkgs.grim}/bin/grim -g "$dims" "$path"
fi
${pkgs.sway}/bin/swaymsg exec -- "echo -n '$path' | ${pkgs.wl-clipboard}/bin/wl-copy --foreground"
${pkgs.libnotify}/bin/notify-send "Screenshot taken" "$path"
''