Skip to content

Commit

Permalink
REBASE: Window Management keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukant Hajra committed Feb 4, 2024
1 parent d5428f9 commit 8f47dcf
Show file tree
Hide file tree
Showing 9 changed files with 509 additions and 398 deletions.
67 changes: 67 additions & 0 deletions build/nixpkgs/packages/i3-scratchpad/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{ nix-project-lib
, coreutils
, i3
, jq
}:

let
progName = "i3-scratchpad";
meta.description = "Manage I3 scratchpad";
in

nix-project-lib.writeShellCheckedExe progName
{
inherit meta;

path = [
coreutils
i3
jq
];
}
''
set -eu
set -o pipefail
main()
{
case "''${1:-}" in
move) move ;;
*) cycle ;;
esac
}
move()
{
if is_in_scratchpad
then
i3-msg floating toggle
else
i3-msg move scratchpad
i3-msg scratchpad show
fi
}
cycle()
{
if is_in_scratchpad
then i3-msg "scratchpad show; scratchpad show"
else i3-msg focus next
fi
}
is_in_scratchpad()
{
i3-msg -t get_tree \
| jq --exit-status '
..
| select(.scratchpad_state? != "none")
| .nodes[]?
| select(.focused == true)
| .id' >/dev/null
}
main "$@"
''
46 changes: 41 additions & 5 deletions build/nixpkgs/packages/i3-workspace-name/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
let
progName = "i3-workspace-name";
meta.description = "Change I3 workspace name interactively";

jqSwapTemplate = cond: op: ''
.
| to_entries as $workspaces
| $workspaces[]
| select(.value.focused==true) as $focused
| if ($focused.key ${cond})
then
$workspaces[]
| select(.key == ($focused.key ${op} 1))
| .value.name
else empty
end
'';
jqSwapPrev = jqSwapTemplate "> 0" "-";
jqSwapNext = jqSwapTemplate "< ($workspaces | length) - 1" "+";

in

nix-project-lib.writeShellCheckedExe progName
Expand All @@ -28,13 +45,32 @@ set -o pipefail
main()
{
local input; input="$(get_input)"
case "''${1:-}" in
prev|next) rename_space "jq_$1" ;;
[0-9]|10) rename_space echo "$1" ;;
*) rename_space get_input ;;
esac
}
rename_space()
{
local input; input="$("$@")"
local trimmed_input; trimmed_input="$(trim "$input")"
if [ -n "$trimmed_input" ]
then smart_rename "$trimmed_input"
fi
}
jq_prev() {
i3-msg -t get_workspaces \
| jq --raw-output '${jqSwapPrev}';
}
jq_next() {
i3-msg -t get_workspaces \
| jq --raw-output '${jqSwapNext}';
}
get_input()
{
rofi -dmenu \
Expand Down Expand Up @@ -78,17 +114,17 @@ name_exists()
rename()
{
orig="$1"
new="$2"
local orig="$1"
local new="$2"
i3-msg "rename workspace \"$orig\" to \"$new\""
}
trim()
{
suffix_trimmed="''${1%%*( )}"
local suffix_trimmed="''${1%%*( )}"
echo "''${suffix_trimmed##*( )}"
}
main
main "$@"
''
4 changes: 2 additions & 2 deletions config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
];
# DESIGN: https://github.com/input-output-hk/hackage.nix/blob/master/index-state-hashes.nix
hackage.index = {
state = "2024-01-24T00:00:00Z";
sha256 = "0b03fc43deb5e1d0ac367a9005d9d02923b0d10a0fccf2891287b6edb1f17a5d";
state = "2024-02-04T00:00:00Z";
sha256 = "0f703fb20c5d0cbddae0e828614e23e4cfd8de6dc97c1006a640afdd2c4947b4";
};
nixpkgs-pin = "nixpkgs-unstable";
};
Expand Down
Loading

0 comments on commit 8f47dcf

Please sign in to comment.