From 9113741910dcc0572dde07015b2fd0f08b1c89bd Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Sat, 6 Apr 2024 03:03:58 +0300 Subject: [PATCH] Migrate completely to Nix configs. --- Makefile | 8 +- flake.nix | 30 +- host/laptop/Configuration.nix | 2 +- module/Docker.nix | 7 +- module/DockerRootless.nix | 7 +- module/NixOnDroid.nix | 34 +- module/Sway.nix | 8 +- module/common/Bash.nix | 7 +- module/common/Firefox.nix | 6 +- module/common/Nvim.nix | 6 +- module/common/Ssh.nix | 6 +- module/common/Tmux.nix | 7 +- module/common/bash/Bash.nix | 60 --- module/common/bash/Init.nix | 25 ++ module/common/bash/module/Android.nix | 20 + module/common/bash/module/Android.sh | 16 - module/common/bash/module/Archive.nix | 397 +++++++++++++++++ module/common/bash/module/Archive.sh | 393 ----------------- module/common/bash/module/Ask.nix | 28 ++ module/common/bash/module/Ask.sh | 24 -- module/common/bash/module/Autocomplete.nix | 87 ++++ module/common/bash/module/Autocomplete.sh | 83 ---- module/common/bash/module/Battery.nix | 16 + module/common/bash/module/Battery.sh | 12 - module/common/bash/module/Bootstrap.nix | 45 ++ module/common/bash/module/Bootstrap.sh | 70 --- module/common/bash/module/Brightness.nix | 22 + module/common/bash/module/Brightness.sh | 18 - module/common/bash/module/Cd.nix | 63 +++ module/common/bash/module/Cd.sh | 59 --- module/common/bash/module/Checksum.nix | 87 ++++ module/common/bash/module/Checksum.sh | 83 ---- module/common/bash/module/Chmod.nix | 9 + module/common/bash/module/Chmod.sh | 5 - module/common/bash/module/Color.nix | 28 ++ module/common/bash/module/Color.sh | 24 -- module/common/bash/module/Container.nix | 84 ++++ module/common/bash/module/Container.sh | 80 ---- module/common/bash/module/Copypaste.nix | 13 + module/common/bash/module/Copypaste.sh | 9 - module/common/bash/module/Cp.nix | 28 ++ module/common/bash/module/Cp.sh | 24 -- module/common/bash/module/Date.nix | 13 + module/common/bash/module/Date.sh | 9 - module/common/bash/module/Dconf.nix | 20 + module/common/bash/module/Dconf.sh | 16 - module/common/bash/module/Disk.nix | 15 + module/common/bash/module/Disk.sh | 11 - module/common/bash/module/Distrobox.nix | 19 + module/common/bash/module/Distrobox.sh | 15 - module/common/bash/module/Dmenu.nix | 15 + module/common/bash/module/Dmenu.sh | 11 - module/common/bash/module/Docker.nix | 99 +++++ module/common/bash/module/Docker.sh | 95 ----- module/common/bash/module/Dvd.nix | 43 ++ module/common/bash/module/Dvd.sh | 39 -- module/common/bash/module/Ffmpeg.nix | 99 +++++ module/common/bash/module/Ffmpeg.sh | 95 ----- module/common/bash/module/File.nix | 28 ++ module/common/bash/module/File.sh | 24 -- module/common/bash/module/Find.nix | 9 + module/common/bash/module/Find.sh | 26 -- module/common/bash/module/Fix.nix | 70 +++ module/common/bash/module/Fix.sh | 66 --- module/common/bash/module/Git.nix | 254 +++++++++++ module/common/bash/module/Git.sh | 250 ----------- module/common/bash/module/Group.nix | 73 ++++ module/common/bash/module/Group.sh | 69 --- module/common/bash/module/Help.nix | 29 ++ module/common/bash/module/Help.sh | 25 -- module/common/bash/module/Ls.nix | 68 +++ module/common/bash/module/Ls.sh | 64 --- module/common/bash/module/Markdown.nix | 19 + module/common/bash/module/Markdown.sh | 15 - module/common/bash/module/Monitor.nix | 13 + module/common/bash/module/Monitor.sh | 9 - module/common/bash/module/Name.nix | 399 ++++++++++++++++++ module/common/bash/module/Name.sh | 395 ----------------- module/common/bash/module/Network.nix | 36 ++ module/common/bash/module/Network.sh | 32 -- module/common/bash/module/Nix.nix | 87 ++++ module/common/bash/module/Nix.sh | 83 ---- module/common/bash/module/Notify.nix | 15 + module/common/bash/module/Notify.sh | 11 - module/common/bash/module/Own.nix | 40 ++ module/common/bash/module/Own.sh | 36 -- module/common/bash/module/Pack.nix | 191 +++++++++ module/common/bash/module/Pack.sh | 187 -------- module/common/bash/module/Parse.nix | 171 ++++++++ module/common/bash/module/Parse.sh | 167 -------- module/common/bash/module/Permission.nix | 13 + module/common/bash/module/Permission.sh | 9 - module/common/bash/module/Power.nix | 13 + module/common/bash/module/Power.sh | 9 - module/common/bash/module/Prune.nix | 28 ++ module/common/bash/module/Prune.sh | 24 -- module/common/bash/module/Ps.nix | 15 + module/common/bash/module/Ps.sh | 11 - module/common/bash/module/Ps1.nix | 157 +++++++ module/common/bash/module/Ps1.sh | 151 ------- module/common/bash/module/Random.nix | 14 + module/common/bash/module/Random.sh | 10 - module/common/bash/module/Recursive.nix | 84 ++++ module/common/bash/module/Recursive.sh | 80 ---- module/common/bash/module/Save.nix | 23 + module/common/bash/module/Save.sh | 19 - module/common/bash/module/Shopt.nix | 27 ++ module/common/bash/module/Shopt.sh | 23 - module/common/bash/module/Sound.nix | 8 + module/common/bash/module/Sound.sh | 4 - module/common/bash/module/Ssh.nix | 22 + module/common/bash/module/Ssh.sh | 18 - module/common/bash/module/Steam.nix | 8 + module/common/bash/module/Steam.sh | 4 - module/common/bash/module/Su.nix | 28 ++ module/common/bash/module/Su.sh | 24 -- module/common/bash/module/Terminal.nix | 10 + module/common/bash/module/Terminal.sh | 6 - module/common/bash/module/Tmp.nix | 20 + module/common/bash/module/Tmp.sh | 16 - module/common/bash/module/Tmux.nix | 98 +++++ module/common/bash/module/Tmux.sh | 94 ----- module/common/bash/module/Todo.nix | 8 + module/common/bash/module/Todo.sh | 4 - module/common/bash/module/Transcode.nix | 101 +++++ module/common/bash/module/Transcode.sh | 97 ----- module/common/bash/module/Try.nix | 25 ++ module/common/bash/module/Try.sh | 21 - module/common/bash/module/Util.nix | 160 +++++++ module/common/bash/module/Util.sh | 156 ------- module/common/bash/module/Vdl.nix | 43 ++ module/common/bash/module/Vdl.sh | 39 -- module/common/bash/module/Vi.nix | 8 + module/common/bash/module/Vi.sh | 4 - module/common/bash/module/Vrr.nix | 13 + module/common/bash/module/Vrr.sh | 9 - module/common/bash/module/Watch.nix | 28 ++ module/common/bash/module/Watch.sh | 24 -- module/common/firefox/Config.js | 35 -- module/common/firefox/Init.nix | 39 ++ module/common/nvim/Init.nix | 102 ++--- module/common/nvim/module/config/Autoread.nix | 9 + module/common/nvim/module/config/Etc.nix | 31 ++ module/common/nvim/module/config/Search.nix | 9 + module/common/nvim/module/config/Tab.nix | 13 + .../common/nvim/module/key/Autocomplete.nix | 9 + module/common/nvim/module/key/Buffer.nix | 16 + module/common/nvim/module/key/Colorscheme.nix | 26 ++ module/common/nvim/module/key/Comment.nix | 9 + module/common/nvim/module/key/Common.nix | 41 ++ module/common/nvim/module/key/Filetree.nix | 6 + module/common/nvim/module/key/Gitsigns.nix | 6 + module/common/nvim/module/key/Leader.nix | 11 + module/common/nvim/module/key/Navigation.nix | 33 ++ module/common/nvim/module/key/Ollama.nix | 8 + module/common/nvim/module/key/Rekey.nix | 53 +++ module/common/nvim/module/key/Sort.nix | 6 + module/common/nvim/module/key/Telescope.nix | 12 + module/common/nvim/module/key/Terminal.nix | 9 + module/common/nvim/module/key/Todo.nix | 6 + module/common/nvim/module/key/Trouble.nix | 6 + module/common/nvim/module/key/Whichkey.nix | 6 + module/common/nvim/module/plugin/Align.nix | 10 + .../common/nvim/module/plugin/Autoclose.nix | 17 + .../common/nvim/module/plugin/Bufferline.nix | 5 + .../nvim/module/plugin/Closebuffers.nix | 11 + .../common/nvim/module/plugin/Colorizer.nix | 8 + module/common/nvim/module/plugin/Filetree.nix | 40 ++ module/common/nvim/module/plugin/Fold.nix | 7 + module/common/nvim/module/plugin/Gitsigns.nix | 47 +++ module/common/nvim/module/plugin/Gruvbox.nix | 19 + module/common/nvim/module/plugin/Indent.nix | 10 + module/common/nvim/module/plugin/Init.nix | 53 +++ module/common/nvim/module/plugin/Ollama.nix | 17 + .../common/nvim/module/plugin/Telescope.nix | 15 + module/common/nvim/module/plugin/Todo.nix | 57 +++ .../common/nvim/module/plugin/Tokyonight.nix | 27 ++ .../common/nvim/module/plugin/Treesitter.nix | 25 ++ module/common/nvim/module/plugin/Trouble.nix | 5 + .../common/nvim/module/plugin/lsp/Haskell.nix | 9 + .../common/nvim/module/plugin/lsp/Kotlin.nix | 7 + module/common/nvim/module/plugin/lsp/Nix.nix | 7 + .../common/nvim/module/plugin/lsp/Python.nix | 7 + module/common/nvim/module/plugin/lsp/Rust.nix | 20 + module/common/nvim/module/plugin/lsp/Tex.nix | 64 +++ module/common/nvim/src/config/Autoread.lua | 5 - module/common/nvim/src/config/Etc.lua | 27 -- module/common/nvim/src/config/Search.lua | 5 - module/common/nvim/src/config/Tab.lua | 9 - module/common/nvim/src/key/Autocomplete.lua | 5 - module/common/nvim/src/key/Buffer.lua | 12 - module/common/nvim/src/key/Colorscheme.lua | 22 - module/common/nvim/src/key/Comment.lua | 5 - module/common/nvim/src/key/Common.lua | 40 -- module/common/nvim/src/key/Filetree.lua | 2 - module/common/nvim/src/key/Gitsigns.lua | 2 - module/common/nvim/src/key/Leader.lua | 7 - module/common/nvim/src/key/Lsp.lua | 0 module/common/nvim/src/key/Navigation.lua | 29 -- module/common/nvim/src/key/Ollama.lua | 2 - module/common/nvim/src/key/Rekey.lua | 49 --- module/common/nvim/src/key/Sort.lua | 2 - module/common/nvim/src/key/Telescope.lua | 6 - module/common/nvim/src/key/Terminal.lua | 5 - module/common/nvim/src/key/Todo.lua | 2 - module/common/nvim/src/key/Trouble.lua | 2 - module/common/nvim/src/key/Update.lua | 5 - module/common/nvim/src/key/Whichkey.lua | 2 - module/common/nvim/src/plugin/Align.lua | 7 - module/common/nvim/src/plugin/Autoclose.lua | 13 - module/common/nvim/src/plugin/Bufferline.lua | 1 - .../common/nvim/src/plugin/Closebuffers.lua | 7 - module/common/nvim/src/plugin/Colorizer.lua | 4 - module/common/nvim/src/plugin/Filetree.lua | 36 -- module/common/nvim/src/plugin/Fold.lua | 3 - module/common/nvim/src/plugin/Gitsigns.lua | 43 -- module/common/nvim/src/plugin/Gruvbox.lua | 15 - module/common/nvim/src/plugin/Indent.lua | 6 - module/common/nvim/src/plugin/Init.lua | 49 --- module/common/nvim/src/plugin/Ollama.lua | 13 - module/common/nvim/src/plugin/Telescope.lua | 11 - module/common/nvim/src/plugin/Todo.lua | 53 --- module/common/nvim/src/plugin/Tokyonight.lua | 23 - module/common/nvim/src/plugin/Treesitter.lua | 21 - module/common/nvim/src/plugin/Trouble.lua | 1 - module/common/nvim/src/plugin/lsp/Haskell.lua | 5 - module/common/nvim/src/plugin/lsp/Kotlin.lua | 3 - module/common/nvim/src/plugin/lsp/Nix.lua | 3 - module/common/nvim/src/plugin/lsp/Python.lua | 3 - module/common/nvim/src/plugin/lsp/Rust.lua | 16 - module/common/nvim/src/plugin/lsp/Tex.lua | 60 --- module/common/ssh/Init.nix | 48 +++ module/common/ssh/config | 44 -- module/common/tmux/Init.nix | 268 ++++++++++++ module/common/tmux/Script.sh | 146 ------- module/common/tmux/tmux.conf | 110 ----- module/desktop/Dconf.nix | 48 ++- module/docker/Init.nix | 7 + module/docker/config.json | 4 - module/sway/Init.nix | 33 ++ module/sway/module/00-Display | 8 - module/sway/module/00-Input | 39 -- module/sway/module/00-Leader | 2 - module/sway/module/10-Font | 1 - module/sway/module/10-Idle | 12 - module/sway/module/10-Launcher | 6 - module/sway/module/10-StatusBar | 14 - module/sway/module/10-Terminal | 4 - module/sway/module/10-TitleBar | 5 - module/sway/module/20-Brightness | 2 - module/sway/module/20-Navigation | 20 - module/sway/module/20-Notification | 5 - module/sway/module/20-Resize | 4 - module/sway/module/20-ScratchPad | 38 -- module/sway/module/20-Screenshot | 5 - module/sway/module/20-Session | 3 - module/sway/module/20-Sound | 3 - module/sway/module/20-Tiling | 37 -- module/sway/module/20-Workspace | 33 -- module/sway/module/Brightness.nix | 8 + module/sway/module/Display.nix | 12 + module/sway/module/Font.nix | 5 + module/sway/module/Input.nix | 43 ++ module/sway/module/Launcher.nix | 17 + module/sway/module/Leader.nix | 6 + module/sway/module/Navigation.nix | 24 ++ module/sway/module/Notification.nix | 9 + module/sway/module/Resize.nix | 8 + module/sway/module/ScratchPad.nix | 42 ++ module/sway/module/Screenshot.nix | 9 + module/sway/module/Sound.nix | 9 + module/sway/{Config.nix => module/Style.nix} | 18 +- module/sway/module/Terminal.nix | 8 + module/sway/module/Tiling.nix | 41 ++ module/sway/module/TitleBar.nix | 9 + module/sway/module/Workspace.nix | 37 ++ part/Key.nix | 145 +++++++ part/Setting.nix | 58 +++ part/Style.nix | 16 +- part/Util.nix | 12 + part/style/Gruvbox.nix | 2 +- user/home/Dasha.nix | 14 +- user/home/Default.nix | 23 +- user/home/Root.nix | 14 +- user/home/Voronind.nix | 14 +- user/home/module/Editorconfig | 21 - user/home/module/editorconfig/Init.nix | 25 ++ user/home/module/foot/{Foot.nix => Init.nix} | 12 +- user/home/module/mako/Init.nix | 14 + user/home/module/mako/Mako.nix | 12 - user/home/module/top/btop/Init.nix | 249 +++++++++++ user/home/module/top/btop/btop.conf | 245 ----------- user/home/module/top/htop/Init.nix | 67 +++ user/home/module/top/htop/htoprc | 63 --- 294 files changed, 6008 insertions(+), 5306 deletions(-) delete mode 100644 module/common/bash/Bash.nix create mode 100644 module/common/bash/Init.nix create mode 100644 module/common/bash/module/Android.nix delete mode 100644 module/common/bash/module/Android.sh create mode 100644 module/common/bash/module/Archive.nix delete mode 100644 module/common/bash/module/Archive.sh create mode 100644 module/common/bash/module/Ask.nix delete mode 100644 module/common/bash/module/Ask.sh create mode 100644 module/common/bash/module/Autocomplete.nix delete mode 100644 module/common/bash/module/Autocomplete.sh create mode 100644 module/common/bash/module/Battery.nix delete mode 100644 module/common/bash/module/Battery.sh create mode 100644 module/common/bash/module/Bootstrap.nix delete mode 100644 module/common/bash/module/Bootstrap.sh create mode 100644 module/common/bash/module/Brightness.nix delete mode 100644 module/common/bash/module/Brightness.sh create mode 100644 module/common/bash/module/Cd.nix delete mode 100644 module/common/bash/module/Cd.sh create mode 100644 module/common/bash/module/Checksum.nix delete mode 100644 module/common/bash/module/Checksum.sh create mode 100644 module/common/bash/module/Chmod.nix delete mode 100644 module/common/bash/module/Chmod.sh create mode 100644 module/common/bash/module/Color.nix delete mode 100644 module/common/bash/module/Color.sh create mode 100644 module/common/bash/module/Container.nix delete mode 100644 module/common/bash/module/Container.sh create mode 100644 module/common/bash/module/Copypaste.nix delete mode 100644 module/common/bash/module/Copypaste.sh create mode 100644 module/common/bash/module/Cp.nix delete mode 100644 module/common/bash/module/Cp.sh create mode 100644 module/common/bash/module/Date.nix delete mode 100644 module/common/bash/module/Date.sh create mode 100644 module/common/bash/module/Dconf.nix delete mode 100644 module/common/bash/module/Dconf.sh create mode 100644 module/common/bash/module/Disk.nix delete mode 100644 module/common/bash/module/Disk.sh create mode 100644 module/common/bash/module/Distrobox.nix delete mode 100644 module/common/bash/module/Distrobox.sh create mode 100644 module/common/bash/module/Dmenu.nix delete mode 100644 module/common/bash/module/Dmenu.sh create mode 100644 module/common/bash/module/Docker.nix delete mode 100644 module/common/bash/module/Docker.sh create mode 100644 module/common/bash/module/Dvd.nix delete mode 100644 module/common/bash/module/Dvd.sh create mode 100644 module/common/bash/module/Ffmpeg.nix delete mode 100644 module/common/bash/module/Ffmpeg.sh create mode 100644 module/common/bash/module/File.nix delete mode 100644 module/common/bash/module/File.sh create mode 100644 module/common/bash/module/Find.nix delete mode 100644 module/common/bash/module/Find.sh create mode 100644 module/common/bash/module/Fix.nix delete mode 100644 module/common/bash/module/Fix.sh create mode 100644 module/common/bash/module/Git.nix delete mode 100644 module/common/bash/module/Git.sh create mode 100644 module/common/bash/module/Group.nix delete mode 100644 module/common/bash/module/Group.sh create mode 100644 module/common/bash/module/Help.nix delete mode 100644 module/common/bash/module/Help.sh create mode 100644 module/common/bash/module/Ls.nix delete mode 100644 module/common/bash/module/Ls.sh create mode 100644 module/common/bash/module/Markdown.nix delete mode 100644 module/common/bash/module/Markdown.sh create mode 100644 module/common/bash/module/Monitor.nix delete mode 100644 module/common/bash/module/Monitor.sh create mode 100644 module/common/bash/module/Name.nix delete mode 100644 module/common/bash/module/Name.sh create mode 100644 module/common/bash/module/Network.nix delete mode 100644 module/common/bash/module/Network.sh create mode 100644 module/common/bash/module/Nix.nix delete mode 100644 module/common/bash/module/Nix.sh create mode 100644 module/common/bash/module/Notify.nix delete mode 100644 module/common/bash/module/Notify.sh create mode 100644 module/common/bash/module/Own.nix delete mode 100644 module/common/bash/module/Own.sh create mode 100644 module/common/bash/module/Pack.nix delete mode 100644 module/common/bash/module/Pack.sh create mode 100644 module/common/bash/module/Parse.nix delete mode 100644 module/common/bash/module/Parse.sh create mode 100644 module/common/bash/module/Permission.nix delete mode 100644 module/common/bash/module/Permission.sh create mode 100644 module/common/bash/module/Power.nix delete mode 100644 module/common/bash/module/Power.sh create mode 100644 module/common/bash/module/Prune.nix delete mode 100644 module/common/bash/module/Prune.sh create mode 100644 module/common/bash/module/Ps.nix delete mode 100644 module/common/bash/module/Ps.sh create mode 100644 module/common/bash/module/Ps1.nix delete mode 100644 module/common/bash/module/Ps1.sh create mode 100644 module/common/bash/module/Random.nix delete mode 100644 module/common/bash/module/Random.sh create mode 100644 module/common/bash/module/Recursive.nix delete mode 100644 module/common/bash/module/Recursive.sh create mode 100644 module/common/bash/module/Save.nix delete mode 100644 module/common/bash/module/Save.sh create mode 100644 module/common/bash/module/Shopt.nix delete mode 100644 module/common/bash/module/Shopt.sh create mode 100644 module/common/bash/module/Sound.nix delete mode 100644 module/common/bash/module/Sound.sh create mode 100644 module/common/bash/module/Ssh.nix delete mode 100644 module/common/bash/module/Ssh.sh create mode 100644 module/common/bash/module/Steam.nix delete mode 100644 module/common/bash/module/Steam.sh create mode 100644 module/common/bash/module/Su.nix delete mode 100644 module/common/bash/module/Su.sh create mode 100644 module/common/bash/module/Terminal.nix delete mode 100644 module/common/bash/module/Terminal.sh create mode 100644 module/common/bash/module/Tmp.nix delete mode 100644 module/common/bash/module/Tmp.sh create mode 100644 module/common/bash/module/Tmux.nix delete mode 100644 module/common/bash/module/Tmux.sh create mode 100644 module/common/bash/module/Todo.nix delete mode 100644 module/common/bash/module/Todo.sh create mode 100644 module/common/bash/module/Transcode.nix delete mode 100644 module/common/bash/module/Transcode.sh create mode 100644 module/common/bash/module/Try.nix delete mode 100644 module/common/bash/module/Try.sh create mode 100644 module/common/bash/module/Util.nix delete mode 100644 module/common/bash/module/Util.sh create mode 100644 module/common/bash/module/Vdl.nix delete mode 100644 module/common/bash/module/Vdl.sh create mode 100644 module/common/bash/module/Vi.nix delete mode 100644 module/common/bash/module/Vi.sh create mode 100644 module/common/bash/module/Vrr.nix delete mode 100644 module/common/bash/module/Vrr.sh create mode 100644 module/common/bash/module/Watch.nix delete mode 100644 module/common/bash/module/Watch.sh delete mode 100644 module/common/firefox/Config.js create mode 100644 module/common/firefox/Init.nix create mode 100644 module/common/nvim/module/config/Autoread.nix create mode 100644 module/common/nvim/module/config/Etc.nix create mode 100644 module/common/nvim/module/config/Search.nix create mode 100644 module/common/nvim/module/config/Tab.nix create mode 100644 module/common/nvim/module/key/Autocomplete.nix create mode 100644 module/common/nvim/module/key/Buffer.nix create mode 100644 module/common/nvim/module/key/Colorscheme.nix create mode 100644 module/common/nvim/module/key/Comment.nix create mode 100644 module/common/nvim/module/key/Common.nix create mode 100644 module/common/nvim/module/key/Filetree.nix create mode 100644 module/common/nvim/module/key/Gitsigns.nix create mode 100644 module/common/nvim/module/key/Leader.nix create mode 100644 module/common/nvim/module/key/Navigation.nix create mode 100644 module/common/nvim/module/key/Ollama.nix create mode 100644 module/common/nvim/module/key/Rekey.nix create mode 100644 module/common/nvim/module/key/Sort.nix create mode 100644 module/common/nvim/module/key/Telescope.nix create mode 100644 module/common/nvim/module/key/Terminal.nix create mode 100644 module/common/nvim/module/key/Todo.nix create mode 100644 module/common/nvim/module/key/Trouble.nix create mode 100644 module/common/nvim/module/key/Whichkey.nix create mode 100644 module/common/nvim/module/plugin/Align.nix create mode 100644 module/common/nvim/module/plugin/Autoclose.nix create mode 100644 module/common/nvim/module/plugin/Bufferline.nix create mode 100644 module/common/nvim/module/plugin/Closebuffers.nix create mode 100644 module/common/nvim/module/plugin/Colorizer.nix create mode 100644 module/common/nvim/module/plugin/Filetree.nix create mode 100644 module/common/nvim/module/plugin/Fold.nix create mode 100644 module/common/nvim/module/plugin/Gitsigns.nix create mode 100644 module/common/nvim/module/plugin/Gruvbox.nix create mode 100644 module/common/nvim/module/plugin/Indent.nix create mode 100644 module/common/nvim/module/plugin/Init.nix create mode 100644 module/common/nvim/module/plugin/Ollama.nix create mode 100644 module/common/nvim/module/plugin/Telescope.nix create mode 100644 module/common/nvim/module/plugin/Todo.nix create mode 100644 module/common/nvim/module/plugin/Tokyonight.nix create mode 100644 module/common/nvim/module/plugin/Treesitter.nix create mode 100644 module/common/nvim/module/plugin/Trouble.nix create mode 100644 module/common/nvim/module/plugin/lsp/Haskell.nix create mode 100644 module/common/nvim/module/plugin/lsp/Kotlin.nix create mode 100644 module/common/nvim/module/plugin/lsp/Nix.nix create mode 100644 module/common/nvim/module/plugin/lsp/Python.nix create mode 100644 module/common/nvim/module/plugin/lsp/Rust.nix create mode 100644 module/common/nvim/module/plugin/lsp/Tex.nix delete mode 100644 module/common/nvim/src/config/Autoread.lua delete mode 100644 module/common/nvim/src/config/Etc.lua delete mode 100644 module/common/nvim/src/config/Search.lua delete mode 100644 module/common/nvim/src/config/Tab.lua delete mode 100644 module/common/nvim/src/key/Autocomplete.lua delete mode 100644 module/common/nvim/src/key/Buffer.lua delete mode 100644 module/common/nvim/src/key/Colorscheme.lua delete mode 100644 module/common/nvim/src/key/Comment.lua delete mode 100644 module/common/nvim/src/key/Common.lua delete mode 100644 module/common/nvim/src/key/Filetree.lua delete mode 100644 module/common/nvim/src/key/Gitsigns.lua delete mode 100644 module/common/nvim/src/key/Leader.lua delete mode 100644 module/common/nvim/src/key/Lsp.lua delete mode 100644 module/common/nvim/src/key/Navigation.lua delete mode 100644 module/common/nvim/src/key/Ollama.lua delete mode 100644 module/common/nvim/src/key/Rekey.lua delete mode 100644 module/common/nvim/src/key/Sort.lua delete mode 100644 module/common/nvim/src/key/Telescope.lua delete mode 100644 module/common/nvim/src/key/Terminal.lua delete mode 100644 module/common/nvim/src/key/Todo.lua delete mode 100644 module/common/nvim/src/key/Trouble.lua delete mode 100644 module/common/nvim/src/key/Update.lua delete mode 100644 module/common/nvim/src/key/Whichkey.lua delete mode 100644 module/common/nvim/src/plugin/Align.lua delete mode 100644 module/common/nvim/src/plugin/Autoclose.lua delete mode 100644 module/common/nvim/src/plugin/Bufferline.lua delete mode 100644 module/common/nvim/src/plugin/Closebuffers.lua delete mode 100644 module/common/nvim/src/plugin/Colorizer.lua delete mode 100644 module/common/nvim/src/plugin/Filetree.lua delete mode 100644 module/common/nvim/src/plugin/Fold.lua delete mode 100644 module/common/nvim/src/plugin/Gitsigns.lua delete mode 100644 module/common/nvim/src/plugin/Gruvbox.lua delete mode 100644 module/common/nvim/src/plugin/Indent.lua delete mode 100644 module/common/nvim/src/plugin/Init.lua delete mode 100644 module/common/nvim/src/plugin/Ollama.lua delete mode 100644 module/common/nvim/src/plugin/Telescope.lua delete mode 100644 module/common/nvim/src/plugin/Todo.lua delete mode 100644 module/common/nvim/src/plugin/Tokyonight.lua delete mode 100644 module/common/nvim/src/plugin/Treesitter.lua delete mode 100644 module/common/nvim/src/plugin/Trouble.lua delete mode 100644 module/common/nvim/src/plugin/lsp/Haskell.lua delete mode 100644 module/common/nvim/src/plugin/lsp/Kotlin.lua delete mode 100644 module/common/nvim/src/plugin/lsp/Nix.lua delete mode 100644 module/common/nvim/src/plugin/lsp/Python.lua delete mode 100644 module/common/nvim/src/plugin/lsp/Rust.lua delete mode 100644 module/common/nvim/src/plugin/lsp/Tex.lua create mode 100644 module/common/ssh/Init.nix delete mode 100644 module/common/ssh/config create mode 100644 module/common/tmux/Init.nix delete mode 100755 module/common/tmux/Script.sh delete mode 100644 module/common/tmux/tmux.conf create mode 100644 module/docker/Init.nix delete mode 100644 module/docker/config.json create mode 100644 module/sway/Init.nix delete mode 100644 module/sway/module/00-Display delete mode 100644 module/sway/module/00-Input delete mode 100644 module/sway/module/00-Leader delete mode 100644 module/sway/module/10-Font delete mode 100644 module/sway/module/10-Idle delete mode 100644 module/sway/module/10-Launcher delete mode 100644 module/sway/module/10-StatusBar delete mode 100644 module/sway/module/10-Terminal delete mode 100644 module/sway/module/10-TitleBar delete mode 100644 module/sway/module/20-Brightness delete mode 100644 module/sway/module/20-Navigation delete mode 100644 module/sway/module/20-Notification delete mode 100644 module/sway/module/20-Resize delete mode 100644 module/sway/module/20-ScratchPad delete mode 100644 module/sway/module/20-Screenshot delete mode 100644 module/sway/module/20-Session delete mode 100644 module/sway/module/20-Sound delete mode 100644 module/sway/module/20-Tiling delete mode 100644 module/sway/module/20-Workspace create mode 100644 module/sway/module/Brightness.nix create mode 100644 module/sway/module/Display.nix create mode 100644 module/sway/module/Font.nix create mode 100644 module/sway/module/Input.nix create mode 100644 module/sway/module/Launcher.nix create mode 100644 module/sway/module/Leader.nix create mode 100644 module/sway/module/Navigation.nix create mode 100644 module/sway/module/Notification.nix create mode 100644 module/sway/module/Resize.nix create mode 100644 module/sway/module/ScratchPad.nix create mode 100644 module/sway/module/Screenshot.nix create mode 100644 module/sway/module/Sound.nix rename module/sway/{Config.nix => module/Style.nix} (63%) create mode 100644 module/sway/module/Terminal.nix create mode 100644 module/sway/module/Tiling.nix create mode 100644 module/sway/module/TitleBar.nix create mode 100644 module/sway/module/Workspace.nix create mode 100644 part/Key.nix create mode 100644 part/Setting.nix create mode 100644 part/Util.nix delete mode 100644 user/home/module/Editorconfig create mode 100644 user/home/module/editorconfig/Init.nix rename user/home/module/foot/{Foot.nix => Init.nix} (64%) create mode 100644 user/home/module/mako/Init.nix delete mode 100644 user/home/module/mako/Mako.nix create mode 100644 user/home/module/top/btop/Init.nix delete mode 100644 user/home/module/top/btop/btop.conf create mode 100644 user/home/module/top/htop/Init.nix delete mode 100644 user/home/module/top/htop/htoprc diff --git a/Makefile b/Makefile index 48cde7c..65658cd 100644 --- a/Makefile +++ b/Makefile @@ -13,10 +13,6 @@ reboot: boot switch: nixos-rebuild switch $(options) --flake $(flake) -.PHONY: trace -trace: check - nixos-rebuild boot $(options) --show-trace --flake $(flake) - .PHONY: update update: nix flake update @@ -33,6 +29,10 @@ android: check: nix flake check +.PHONY: trace +trace: + nix flake check --show-trace + .PHONY: show show: nix flake show diff --git a/flake.nix b/flake.nix index f6ea900..e379a1d 100644 --- a/flake.nix +++ b/flake.nix @@ -139,7 +139,7 @@ ]; # Function to create a host. - mkHost = { system, hostname, modules }: nixpkgs.lib.nixosSystem { + mkHost = { system, hostname, modules } @args: nixpkgs.lib.nixosSystem { inherit system; modules = [ @@ -151,12 +151,18 @@ stylix.nixosModules.stylix ] ++ modules; - specialArgs = { + specialArgs = let + pkgs = nixpkgs.legacyPackages.${system}.pkgs; + config = self.nixosConfigurations.${hostname}.config; + in { const = self.nixosModules.const; flake = self; inputs = inputs; - style = import ./part/Style.nix { config = self.nixosConfigurations.${hostname}.config; }; - wallpaper = import ./part/Wallpaper.nix { pkgs = nixpkgs.legacyPackages.${system}.pkgs; }; + key = import ./part/Key.nix {}; + setting = import ./part/Setting.nix {}; + style = import ./part/Style.nix { config = config; }; + util = import ./part/Util.nix { pkgs = pkgs; }; + wallpaper = import ./part/Wallpaper.nix { pkgs = pkgs; }; }; }; @@ -265,11 +271,17 @@ { system.stateVersion = inputs.self.nixosModules.const.droidStateVersion; } ./module/NixOnDroid.nix ]; - extraSpecialArgs = { - const = self.nixosModules.const; - flake = self; - inputs = inputs; - style = import ./part/Style.nix { config = import ./part/style/Gruvbox.nix {}; }; + + extraSpecialArgs = let + pkgs = nixpkgs.legacyPackages."aarch64-linux".pkgs; + in { + const = self.nixosModules.const; + flake = self; + inputs = inputs; + key = import ./part/Key.nix {}; + setting = import ./part/Setting.nix {}; + style = import ./part/Style.nix { config = import ./part/style/Gruvbox.nix {}; }; + util = import ./part/Util.nix { pkgs = pkgs; }; }; }; }; diff --git a/host/laptop/Configuration.nix b/host/laptop/Configuration.nix index 9040344..4d0246a 100644 --- a/host/laptop/Configuration.nix +++ b/host/laptop/Configuration.nix @@ -1,4 +1,4 @@ -{ ... }: { +{ lib, ... }: { imports = [ ./Filesystem.nix ../dasha/Tablet.nix diff --git a/module/Docker.nix b/module/Docker.nix index 72f50cf..af4f3ba 100644 --- a/module/Docker.nix +++ b/module/Docker.nix @@ -1,4 +1,7 @@ -{ ... }: { - environment.variables.DOCKER_CONFIG = ./docker; +{ pkgs, key, util, ... } @args: let + docker = import ./docker/Init.nix args; + config = pkgs.writeText "dockerConfig" docker.text; +in { + environment.variables.DOCKER_CONFIG = config; virtualisation.docker.enable = true; } diff --git a/module/DockerRootless.nix b/module/DockerRootless.nix index 2b66d5b..ac367ef 100644 --- a/module/DockerRootless.nix +++ b/module/DockerRootless.nix @@ -1,5 +1,8 @@ -{ ... }: { - environment.variables.DOCKER_CONFIG = ./docker; +{ pkgs, key, util, ... } @args: let + docker = import ./docker/Init.nix args; + config = pkgs.writeText "dockerConfig" docker.text; +in { + environment.variables.DOCKER_CONFIG = config; virtualisation.docker.enable = true; virtualisation.docker.rootless = { enable = true; diff --git a/module/NixOnDroid.nix b/module/NixOnDroid.nix index 910ceb3..51395c8 100644 --- a/module/NixOnDroid.nix +++ b/module/NixOnDroid.nix @@ -1,7 +1,17 @@ -{ pkgs, inputs, const, style, ... }: let +{ pkgs, inputs, const, style, util, key, setting, ... } @args: let homePath = "/data/data/com.termux.nix/files/home"; - tmuxScript = pkgs.writeShellScriptBin "tmux_script" (builtins.readFile ./common/tmux/Script.sh); - bash = import ./common/bash/Bash.nix { style = style; }; + tmux = import ./common/tmux/Init.nix args; + tmuxScript = pkgs.writeShellScriptBin "tmux_script" tmux.script; + bash = import ./common/bash/Init.nix args; + nvim = import ./common/nvim/Init.nix args; + ssh = import ./common/ssh/Init.nix args; + font = pkgs.runCommandNoCC "font" {} '' + cp ${pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }}/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out + ''; + colors = '' + background=#${style.color.bg.dark} + foreground=#${style.color.fg.light} + ''; in { # NOTE: Split into modules? environment.packages = with pkgs; [ @@ -52,18 +62,12 @@ in { home-manager.config = { home.stateVersion = const.droidStateVersion; home.file = { - ".dotfiles".source = inputs.self; - ".ssh/config".source = ./common/ssh/config; - ".termux/_font.ttf".source = pkgs.runCommandNoCC "font" {} '' - cp ${pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }}/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out - ''; - ".termux/_colors.properties".text = '' - background=#${style.color.bg_dark} - foreground=#${style.color.fg} - ''; + ".dotfiles".source = inputs.self; + ".ssh/config".text = ssh.config; + ".termux/_font.ttf".source = font; + ".termux/_colors.properties".text = colors; }; home.sessionVariables = { - BASH_PATH = ./common/bash; EDITOR = "nvim"; MANPAGER = "nvim +Man!"; NIXPKGS_ALLOW_UNFREE = "1"; @@ -82,7 +86,7 @@ in { }; programs.tmux = { enable = true; - extraConfig = builtins.readFile ./common/tmux/tmux.conf; + extraConfig = tmux.config; }; programs.git = { enable = true; @@ -98,7 +102,7 @@ in { enable = true; viAlias = true; vimAlias = true; - extraConfig = (import ./common/nvim/Init.nix { inputs = inputs; }).customRc; + extraConfig = nvim.config; }; }; } diff --git a/module/Sway.nix b/module/Sway.nix index 70dbfff..c7f0da4 100644 --- a/module/Sway.nix +++ b/module/Sway.nix @@ -1,5 +1,6 @@ -{ pkgs, lib, wallpaper, style, ... }: let - sway = import ./sway/Config.nix { pkgs = pkgs; wallpaper = wallpaper; style = style; }; +{ pkgs, lib, wallpaper, style, ... } @args: let + sway = import ./sway/Init.nix args; + config = pkgs.writeText "swayConfig" sway.config; in { imports = [ ./desktop/App.nix @@ -28,13 +29,12 @@ in { gtk = true; }; extraOptions = [ - "--config=${sway.config}" + "--config=${config}" ]; }; environment = { variables = { - SWAY_CONFIG = ./sway/module; SWAY_IWT_PATH = "${pkgs.sway-contrib.inactive-windows-transparency}/bin/inactive-windows-transparency.py"; # PATH = [ "/etc/swaybin" ]; # NOTE: Kept as an example on PATH modification. }; diff --git a/module/common/Bash.nix b/module/common/Bash.nix index 3c3328a..db17cb6 100644 --- a/module/common/Bash.nix +++ b/module/common/Bash.nix @@ -1,10 +1,9 @@ -{ lib, style, ... }: let - bash = import ./bash/Bash.nix { style = style; }; +{ lib, style, util, pkgs, ... } @args: let + bash = import ./bash/Init.nix args; in { programs.bash.interactiveShellInit = bash.config; environment.shellAliases = lib.mkForce {}; environment.variables = { - BASH_PATH = ./bash; - TERM = "xterm-256color"; + TERM = "xterm-256color"; }; } diff --git a/module/common/Firefox.nix b/module/common/Firefox.nix index 71dc04a..9a92336 100644 --- a/module/common/Firefox.nix +++ b/module/common/Firefox.nix @@ -1,4 +1,6 @@ -{ pkgs, ... }: { +{ pkgs, util, ... } @args: let + firefox = import ./firefox/Init.nix args; +in { # Disable profile switching on rebuild. environment.variables = { MOZ_LEGACY_PROFILES = "1"; @@ -8,7 +10,7 @@ enable = true; package = pkgs.firefox-esr; languagePacks = [ "en-US" "ru" ]; - autoConfig = builtins.readFile ./firefox/Config.js; + autoConfig = firefox.config; policies = { ManagedBookmarks = [ { diff --git a/module/common/Nvim.nix b/module/common/Nvim.nix index 14a6632..7b74c2b 100644 --- a/module/common/Nvim.nix +++ b/module/common/Nvim.nix @@ -1,5 +1,5 @@ -{ inputs, pkgs, ... }: let - nvimCfg = import ./nvim/Init.nix { inputs = inputs; }; +{ inputs, pkgs, util, key, setting, ... } @args: let + nvim = import ./nvim/Init.nix args; in { environment = { variables = { @@ -15,7 +15,7 @@ in { viAlias = true; vimAlias = true; configure = { - customRC = nvimCfg.customRc; + customRC = nvim.config; }; }; } diff --git a/module/common/Ssh.nix b/module/common/Ssh.nix index e57dfcf..ff7938c 100644 --- a/module/common/Ssh.nix +++ b/module/common/Ssh.nix @@ -1,4 +1,6 @@ -{ pkgs, ... }: { +{ pkgs, util, ... } @args: let + ssh = import ./ssh/Init.nix args; +in { environment.systemPackages = with pkgs; [ sshfs ]; - programs.ssh.extraConfig = builtins.readFile ./ssh/config; + programs.ssh.extraConfig = ssh.config; } diff --git a/module/common/Tmux.nix b/module/common/Tmux.nix index 5e4c3a5..a39529e 100644 --- a/module/common/Tmux.nix +++ b/module/common/Tmux.nix @@ -1,9 +1,10 @@ -{ pkgs, ... }: let - script = pkgs.writeShellScriptBin "tmux_script" (builtins.readFile ./tmux/Script.sh); +{ pkgs, style, key, util, ... } @args: let + tmux = import ./tmux/Init.nix args; + script = pkgs.writeShellScriptBin "tmux_script" tmux.script; in { programs.tmux = { enable = true; - extraConfig = builtins.readFile ./tmux/tmux.conf; + extraConfig = tmux.config; }; environment.systemPackages = [ script ]; } diff --git a/module/common/bash/Bash.nix b/module/common/bash/Bash.nix deleted file mode 100644 index 054e5d7..0000000 --- a/module/common/bash/Bash.nix +++ /dev/null @@ -1,60 +0,0 @@ -{ style, ... }: let - accent-b = style.color.accent-b; - accent-g = style.color.accent-g; - accent-r = style.color.accent-r; - negative-b = style.color.negative-b; - negative-g = style.color.negative-g; - negative-r = style.color.negative-r; - neutral-b = style.color.neutral-b; - neutral-g = style.color.neutral-g; - neutral-r = style.color.neutral-r; - positive-b = style.color.positive-b; - positive-g = style.color.positive-g; - positive-r = style.color.positive-r; - - accent = style.color.accent; - bg = style.color.bg_dark; - fg = style.color.fg_light; - - fontNamePopup = style.font.serif.name; - fontSizePopup = style.font.size.popup; -in { - config = '' - # If not running interactively, don't do anything. - [[ "$-" != *i* ]] && return - - # Src system bashrc. - [[ -f /etc/bashrc ]] && source /etc/bashrc - - # Define colors. - export negative_rgb="${negative-r};${negative-g};${negative-b}" - export neutral_rgb="${neutral-r};${neutral-g};${neutral-b}" - export positive_rgb="${positive-r};${positive-g};${positive-b}" - export accent_rgb="${accent-r};${accent-g};${accent-b}" - export bg="${bg}" - export fg="${fg}" - export accent="${accent}" - - # Define font. - export font_name_popup="${fontNamePopup}" - export font_size_popup="${toString(fontSizePopup)}" - - # Src custom modules. - for module in $BASH_PATH/module/*.sh; do - source "$module" - done - - # Alias to reload. - function bashrc() { - source $BASH_PATH/Bashrc.sh - } - - # Export all functions. - export -f $(find_function | tr '\n' ' ') - - # Autostart Sway. - if [[ -z $DISPLAY ]] && [[ "$(tty)" = "/dev/tty1" ]]; then - exec sway - fi - ''; -} diff --git a/module/common/bash/Init.nix b/module/common/bash/Init.nix new file mode 100644 index 0000000..40d4fa1 --- /dev/null +++ b/module/common/bash/Init.nix @@ -0,0 +1,25 @@ +{ style, util, pkgs, ... } @args: let + bashRc = pkgs.writeText "bashRc" (util.trimTabs (builtins.foldl' (acc: mod: + acc + (import mod args).text + ) "" (util.ls ./module))); +in { + config = util.trimTabs ('' + # If not running interactively, don't do anything. + [[ "$-" != *i* ]] && return + + '' + builtins.readFile bashRc + '' + + # Find all functions. + function find_function() { + /usr/bin/env cat ${bashRc} | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//" + } + + # Export all functions. + export -f $(find_function | tr '\n' ' ') + + # Autostart Sway. + if [[ -z $DISPLAY ]] && [[ "$(tty)" = "/dev/tty1" ]]; then + exec sway + fi + ''); +} diff --git a/module/common/bash/module/Android.nix b/module/common/bash/module/Android.nix new file mode 100644 index 0000000..f7a6f13 --- /dev/null +++ b/module/common/bash/module/Android.nix @@ -0,0 +1,20 @@ +{ ... }: { + text = '' + # Start an Android emulator. + # Default name is `main`. + # Usage: emulator [NAME] + function emulator() { + local name="$1" + + [[ "$name" = "" ]] && name="main" + + steam-run ~/.android/sdk/emulator/emulator -avd "$name" &> /dev/null & disown + } + + function _android_emulators() { + _autocomplete_first $(ls --classify ~/.android/avd/ | grep \/$ | sed -e "s/.avd\/$//") + } + + complete -F _android_emulators emulator + ''; +} diff --git a/module/common/bash/module/Android.sh b/module/common/bash/module/Android.sh deleted file mode 100644 index 4096d4d..0000000 --- a/module/common/bash/module/Android.sh +++ /dev/null @@ -1,16 +0,0 @@ -# Start an Android emulator. -# Default name is `main`. -# Usage: emulator [NAME] -function emulator() { - local name="${1}" - - [[ "${name}" = "" ]] && name="main" - - steam-run ~/.android/sdk/emulator/emulator -avd "${name}" &> /dev/null & disown -} - -function _android_emulators() { - _autocomplete_first $(ls --classify ~/.android/avd/ | grep \/$ | sed -e "s/.avd\/$//") -} - -complete -F _android_emulators emulator diff --git a/module/common/bash/module/Archive.nix b/module/common/bash/module/Archive.nix new file mode 100644 index 0000000..593f573 --- /dev/null +++ b/module/common/bash/module/Archive.nix @@ -0,0 +1,397 @@ +{ ... }: { + text = '' + export _archive_pattern="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z$" + export _archive_pattern_fast="_[0-9]{12}-[[:alnum:]]{40}.tgz$" + + # Archive directories. + # All directories by default. + # Supports .archiveignore exclude file. + # Usage: archive [DIRS] + function archive() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_dir)) + + process() { + local date=$(_archive_date) + + # Parse name. + local name=$(parse_pascal ''${target}) + + # Exclude support. + local exclude="" + [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" + [[ -f "''${target}/.archiveignore" ]] && exclude="--exclude-from=''${target}/.archiveignore" + + # Create archive. + local hash=$(tar ''${exclude} -c ''${target} | pv -s $(/usr/bin/env du -sb ''${target} | awk '{print $1}') | xz -9e --threads=1 | tee ''${name}.txz | sha1sum | cut -d\ -f1) + + # Append hash to target name. + local new_name="''${name}_''${date}-''${hash}.txz" + mv -- ''${name}.txz ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Archive using multiple threads. Uses 75% of free RAM. + # All directories by default. + # Supports .archiveignore exclude file. + # Usage: archive_mt [DIRS] + function archive_mt() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_dir)) + + process() { + local date=$(_archive_date) + + # Parse name. + local name=$(parse_pascal ''${target}) + + # Exclude support. + local exclude="" + [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" + [[ -f "''${target}/.archiveignore" ]] && exclude="--exclude-from=''${target}/.archiveignore" + + # Determine memory limit. + local mem_free=$(_mem_free) + local mem_limit=$((mem_free*3/4)) + + # Create archive. + local hash=$(tar ''${exclude} -c ''${target} | pv -s $(/usr/bin/env du -sb ''${target} | awk '{print $1}') | xz -9e --threads=0 --memlimit=''${mem_limit}MiB | tee ''${name}.txz | sha1sum | cut -d\ -f1) + + # Append hash to target name. + local new_name="''${name}_''${date}-''${hash}.txz" + mv -- ''${name}.txz ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Archive directories with fast compression. + # All directories by default. + # Supports .archiveignore exclude file. + # Usage: archive_fast [DIRS] + function archive_fast() { + local IFS=$'\n' + local targets=("''${@}") + [[ "''${targets}" = "" ]] && targets=($(_ls_dir)) + + process() { + # Start timestamp. + local date=$(_archive_date) + + # Parse name. + local name=$(parse_pascal "''${target}") + + # Exclude support. + local exclude="" + [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" + [[ -f "''${target}/.archiveignore" ]] && exclude="--exclude-from=''${target}/.archiveignore" + + # Create archive. + local hash=$(tar ''${exclude} -c "''${target}" | pv -s $(/usr/bin/env du -sb "''${target}" | awk '{print $1}') | gzip -1 | tee "''${name}".tgz | sha1sum | cut -d\ -f1) + + # Append hash to target name. + local new_name="''${name}_''${date}-''${hash}.tgz" + mv -- "''${name}".tgz ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Check archives integrity. + # Checks all archives by default. + # Usage: archive_check [FILES] + function archive_check() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) + + process() { + _archive_check "''${target}" + } + + _iterate_targets process ''${targets[@]} + } + + # Delete old versions of an archive. + # All archives with 1 version by default. + # Usage: archive_prune [NAME] [VERSIONS] + function archive_prune() { + local IFS=$'\n' + local targets=(''${1}) + local versions=''${2} + + [[ "''${targets}" = "" ]] && targets=($(_archive_names)) + [[ "''${versions}" = "" ]] && versions=1 + + if [[ ''${#} -gt 2 ]]; then + help archive_prune + return 2 + fi + + process() { + local prune=($(ls | grep -E "^''${target}''${_archive_pattern}" | sort -r | sed -e "1,''${versions}d")) + + for archive in ''${prune[@]}; do + rm -- "''${archive}" && echo "''${archive}" + done + } + + _iterate_targets process ''${targets[@]} + } + + # Delete specified or all archive files. + # Usage: archive_rm [FILES] + function archive_rm() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) + + process() { + rm -- "''${target}" && echo "''${target}" + } + + _iterate_targets process ''${targets[@]} + } + + # Recompress previously created archive_fast with better compression. + # Usage: archive_xz [FILES] + function archive_xz() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=$(_ls_archive_fast) + + process() { + local data=($(_archive_parse "''${target}")) + local tmp="''${data[0]}.txz" + + # Check that old format. + if [[ "''${data[3]}" != "tgz" ]]; then + _error "Not in .tgz format!" + return 1 + fi + + # Check integrity. + _archive_check "''${target}" || return 1 + + # Recompress. + local hash=$(pv "''${target}" | gzip -d | xz -9e --threads=1 | tee "''${tmp}" | sha1sum | cut -d\ -f1) + + # Rename. + local new_name="''${data[0]}_''${data[1]}-''${hash}.txz" + mv -- ''${tmp} ''${new_name} && rm ''${target} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename archives. + # If no name specified, it simplifies archive's name. + # If no archives specified, apply to all archives. + # Usage: archive_name [ARCHIVE] [NAME] + function archive_name() { + local IFS=$'\n' + local targets="''${1}" + local name="''${2}" + [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) + + process() { + # Simplify name by default. + if [[ "''${name}" = "" || ''${count} -gt 1 ]]; then + name="''${target%_*}" + name="$(parse_pascal ''${name})" + fi + + # Remove old name. + local data="''${target##*_}" + local new_name="''${name}_''${data}" + + # Check for the same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Check for existing target. + if [[ -f "''${new_name}" ]]; then + _error "''${new_name}: Already exists!" + return 1 + fi + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Extract previously created archive with checksum validation. + # Supports unarchiving exact paths from the remote machines (rsync syntax). + # Usage: unarchive [HOST:FILES] + function unarchive() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=$(_ls_archive) + + process() { + # Validate. + # _archive_check "''${target}" || return 1 + if ! _is_archive "''${target}"; then + _iterate_skip "Not an archive." + return 0 + fi + + # Remote archives. + local remote + local file="''${target}" + + if [[ "''${target//\\:/}" == *:* ]]; then + local host="''${target%%:*}" + file="''${target#*:}" + remote=(sudo ssh ''${host}) + fi + + # Extract. + case "''${file##*.}" in + "txz") + ''${remote[@]} pv -f ''${file} | xz -d | tar -xf - + ;; + "tgz") + ''${remote[@]} pv -f ''${file} | gzip -d | tar -xf - + ;; + esac + } + + _iterate_targets process ''${targets[@]} + } + + # Change archive's filesystem time to match creation date. + # Usage: archive_touch [FILES] + function archive_touch() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=$(_ls_archive) + + process() { + local data=($(_archive_parse "''${target}")) + local date=''${data[1]} + touch -t ''${date} -- ''${target} + } + + _iterate_targets process ''${targets[@]} + } + + # Parse archive file name to get: name, date, hash and format. + # Usage: _archive_parse + function _archive_parse() { + local input="''${1}" + local name="''${input%_*}" + local format="''${input##*.}" + local data="''${input##*_}"; data="''${data%.*}" + local date="''${data%%-*}" + local hash="''${data##*-}" + + echo "''${name}" + echo "''${date}" + echo "''${hash}" + echo "''${format}" + } + + # Autocomplete for archive_name function. + # First arg is the archives list, second one is selected archive's current name. + function _comp_archive_name() { + local IFS=$'\n' + COMPREPLY=() + + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" + + if [[ "''${prev}" = "''${command}" ]]; then + COMPREPLY=( $(compgen -W "$(ls | grep -E ''${_archive_pattern})" -- ''${cur}) ) + return 0 + else + local data=($(_archive_parse ''${prev})) + local name="''${data[0]}" + COMPREPLY=( $(compgen -W "''${name}" -- ''${cur}) ) + return 0 + fi + } + + # Autocomplete with archives in current dir. + function _comp_archive_grep() { + _autocomplete_grep ''${_archive_pattern} + } + + # Autocomplete with fast archives in current dir. + function _comp_archive_grep_fast() { + _autocomplete_grep ''${_archive_pattern_fast} + } + + # Get date for a new archive. + function _archive_date() { + date +%Y%m%d%H%M + } + + # Get names of all archives. + function _archive_names() { + local IFS=$'\n' + local archives=($(_ls_archive)) + local names=() + + for archive in ''${archives[@]}; do + local data=($(_archive_parse ''${archive})) + names+=(''${data[0]}) + done + + # Remove copies. + names=($(printf '%s\n' "''${names[@]}" | sort -u)) + + printf '%s\n' "''${names[@]}" + } + + # Autocomplete with names of all archives. + function _comp_archive_names() { + _autocomplete_first $(_archive_names) + } + + # Check if file is an archive. + function _is_archive() { + local out=$(echo "''${*}" | grep -E ''${_archive_pattern}) + + [[ "''${out}" != "" ]] + } + + # List all archives. + function _ls_archive() { + ls | grep -E ''${_archive_pattern} + } + + # List fast archives. + function _ls_archive_fast() { + ls | grep -E ''${_archive_pattern_fast} + } + + # Filter input for archives only. + function _filter_archive() { + grep -E ''${_archive_pattern} + } + + function _archive_check() { + # Extract hash from name. + local data=($(_archive_parse ''${target})) + local saved=''${data[2]} + + # Calculate actual hash. + local actual=$(pv ''${target} | sha1sum | cut -d\ -f1) + + # Compare hashes. + [[ "''${actual}" = "''${saved}" ]] + } + + # complete -o filenames -F _comp_archive_grep archive_check unarchive archive_rm archive_touch + # complete -o filenames -F _comp_archive_grep_fast archive_xz + complete -o filenames -F _comp_archive_name archive_name + complete -o filenames -F _comp_archive_names archive_prune + ''; +} diff --git a/module/common/bash/module/Archive.sh b/module/common/bash/module/Archive.sh deleted file mode 100644 index 3847094..0000000 --- a/module/common/bash/module/Archive.sh +++ /dev/null @@ -1,393 +0,0 @@ -export _archive_pattern="_[0-9]{12}-[[:alnum:]]{40}.t[xg]z$" -export _archive_pattern_fast="_[0-9]{12}-[[:alnum:]]{40}.tgz$" - -# Archive directories. -# All directories by default. -# Supports .archiveignore exclude file. -# Usage: archive [DIRS] -function archive() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_dir)) - - process() { - local date=$(_archive_date) - - # Parse name. - local name=$(parse_pascal ${target}) - - # Exclude support. - local exclude="" - [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" - [[ -f "${target}/.archiveignore" ]] && exclude="--exclude-from=${target}/.archiveignore" - - # create archive. - local hash=$(tar ${exclude} -c ${target} | pv -s $(/usr/bin/env du -sb ${target} | awk '{print $1}') | xz -9e --threads=1 | tee ${name}.txz | sha1sum | cut -d\ -f1) - - # append hash to target name. - local new_name="${name}_${date}-${hash}.txz" - mv -- ${name}.txz ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Archive using multiple threads. Uses 75% of free RAM. -# All directories by default. -# Supports .archiveignore exclude file. -# Usage: archive_mt [DIRS] -function archive_mt() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_dir)) - - process() { - local date=$(_archive_date) - - # Parse name. - local name=$(parse_pascal ${target}) - - # Exclude support. - local exclude="" - [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" - [[ -f "${target}/.archiveignore" ]] && exclude="--exclude-from=${target}/.archiveignore" - - # Determine memory limit. - local mem_free=$(_mem_free) - local mem_limit=$((mem_free*3/4)) - - # create archive. - local hash=$(tar ${exclude} -c ${target} | pv -s $(/usr/bin/env du -sb ${target} | awk '{print $1}') | xz -9e --threads=0 --memlimit=${mem_limit}MiB | tee ${name}.txz | sha1sum | cut -d\ -f1) - - # append hash to target name. - local new_name="${name}_${date}-${hash}.txz" - mv -- ${name}.txz ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Archive directories with fast compression. -# All directories by default. -# Supports .archiveignore exclude file. -# Usage: archive_fast [DIRS] -function archive_fast() { - local IFS=$'\n' - local targets=("${@}") - [[ "${targets}" = "" ]] && targets=($(_ls_dir)) - - process() { - # Start timestamp. - local date=$(_archive_date) - - # Parse name. - local name=$(parse_pascal "${target}") - - # Exclude support. - local exclude="" - [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" - [[ -f "${target}/.archiveignore" ]] && exclude="--exclude-from=${target}/.archiveignore" - - # create archive. - local hash=$(tar ${exclude} -c "${target}" | pv -s $(/usr/bin/env du -sb "${target}" | awk '{print $1}') | gzip -1 | tee "${name}".tgz | sha1sum | cut -d\ -f1) - - # append hash to target name. - local new_name="${name}_${date}-${hash}.tgz" - mv -- "${name}".tgz ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Check archives integrity. -# Checks all archives by default. -# Usage: archive_check [FILES] -function archive_check() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_archive)) - - process() { - _archive_check "${target}" - } - - _iterate_targets process ${targets[@]} -} - -# Delete old versions of an archive. -# All archives with 1 version by default. -# Usage: archive_prune [NAME] [VERSIONS] -function archive_prune() { - local IFS=$'\n' - local targets=(${1}) - local versions=${2} - - [[ "${targets}" = "" ]] && targets=($(_archive_names)) - [[ "${versions}" = "" ]] && versions=1 - - if [[ ${#} -gt 2 ]]; then - help archive_prune - return 2 - fi - - process() { - local prune=($(ls | grep -E "^${target}${_archive_pattern}" | sort -r | sed -e "1,${versions}d")) - - for archive in ${prune[@]}; do - rm -- "${archive}" && echo "${archive}" - done - } - - _iterate_targets process ${targets[@]} -} - -# Delete specified or all archive files. -# Usage: archive_rm [FILES] -function archive_rm() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_archive)) - - process() { - rm -- "${target}" && echo "${target}" - } - - _iterate_targets process ${targets[@]} -} - -# Recompress previously created archive_fast with better compression. -# Usage: archive_xz [FILES] -function archive_xz() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=$(_ls_archive_fast) - - process() { - local data=($(_archive_parse "${target}")) - local tmp="${data[0]}.txz" - - # Check that old format. - if [[ "${data[3]}" != "tgz" ]]; then - _error "Not in .tgz format!" - return 1 - fi - - # Check integrity. - _archive_check "${target}" || return 1 - - # Recompress. - local hash=$(pv "${target}" | gzip -d | xz -9e --threads=1 | tee "${tmp}" | sha1sum | cut -d\ -f1) - - # Rename. - local new_name="${data[0]}_${data[1]}-${hash}.txz" - mv -- ${tmp} ${new_name} && rm ${target} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Rename archives. -# If no name specified, it simplifies archive's name. -# If no archives specified, apply to all archives. -# Usage: archive_name [ARCHIVE] [NAME] -function archive_name() { - local IFS=$'\n' - local targets="${1}" - local name="${2}" - [[ "${targets}" = "" ]] && targets=($(_ls_archive)) - - process() { - # simplify name by default. - if [[ "${name}" = "" || ${count} -gt 1 ]]; then - name="${target%_*}" - name="$(parse_pascal ${name})" - fi - - # remove old name. - local data="${target##*_}" - local new_name="${name}_${data}" - - # check for the same name. - [[ "${target}" = "${new_name}" ]] && return 0 - - # check for existing target. - if [[ -f "${new_name}" ]]; then - _error "${new_name}: Already exists!" - return 1 - fi - - # rename. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Extract previously created archive with checksum validation. -# Supports unarchiving exact paths from the remote machines (rsync syntax). -# Usage: unarchive [HOST:FILES] -function unarchive() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=$(_ls_archive) - - process() { - # Validate. - # _archive_check "${target}" || return 1 - if ! _is_archive "${target}"; then - _iterate_skip "Not an archive." - return 0 - fi - - # Remote archives. - local remote - local file="${target}" - - if [[ "${target//\\:/}" == *:* ]]; then - local host="${target%%:*}" - file="${target#*:}" - remote=(sudo ssh ${host}) - fi - - # Extract. - case "${file##*.}" in - "txz") - ${remote[@]} pv -f ${file} | xz -d | tar -xf - - ;; - "tgz") - ${remote[@]} pv -f ${file} | gzip -d | tar -xf - - ;; - esac - } - - _iterate_targets process ${targets[@]} -} - -# Change archive's filesystem time to match creation date. -# Usage: archive_touch [FILES] -function archive_touch() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=$(_ls_archive) - - process() { - local data=($(_archive_parse "${target}")) - local date=${data[1]} - touch -t ${date} -- ${target} - } - - _iterate_targets process ${targets[@]} -} - -# Parse archive file name to get: name, date, hash and format. -# Usage: _archive_parse -function _archive_parse() { - local input="${1}" - local name="${input%_*}" - local format="${input##*.}" - local data="${input##*_}"; data="${data%.*}" - local date="${data%%-*}" - local hash="${data##*-}" - - echo "${name}" - echo "${date}" - echo "${hash}" - echo "${format}" -} - -# Autocomplete for archive_name function. -# First arg is the archives list, second one is selected archive's current name. -function _comp_archive_name() { - local IFS=$'\n' - COMPREPLY=() - - local cur="${COMP_WORDS[COMP_CWORD]}" - local prev="${COMP_WORDS[COMP_CWORD-1]}" - local command="${COMP_WORDS[0]}" - - if [[ "${prev}" = "${command}" ]]; then - COMPREPLY=( $(compgen -W "$(ls | grep -E ${_archive_pattern})" -- ${cur}) ) - return 0 - else - local data=($(_archive_parse ${prev})) - local name="${data[0]}" - COMPREPLY=( $(compgen -W "${name}" -- ${cur}) ) - return 0 - fi -} - -# Autocomplete with archives in current dir. -function _comp_archive_grep() { - _autocomplete_grep ${_archive_pattern} -} - -# Autocomplete with fast archives in current dir. -function _comp_archive_grep_fast() { - _autocomplete_grep ${_archive_pattern_fast} -} - -# Get date for a new archive. -function _archive_date() { - date +%Y%m%d%H%M -} - -# Get names of all archives. -function _archive_names() { - local IFS=$'\n' - local archives=($(_ls_archive)) - local names=() - - for archive in ${archives[@]}; do - local data=($(_archive_parse ${archive})) - names+=(${data[0]}) - done - - # Remove copies. - names=($(printf '%s\n' "${names[@]}" | sort -u)) - - printf '%s\n' "${names[@]}" -} - -# Autocomplete with names of all archives. -function _comp_archive_names() { - _autocomplete_first $(_archive_names) -} - -# Check if file is an archive. -function _is_archive() { - local out=$(echo "${*}" | grep -E ${_archive_pattern}) - - [[ "${out}" != "" ]] -} - -# List all archives. -function _ls_archive() { - ls | grep -E ${_archive_pattern} -} - -# List fast archives. -function _ls_archive_fast() { - ls | grep -E ${_archive_pattern_fast} -} - -# Filter input for archives only. -function _filter_archive() { - grep -E ${_archive_pattern} -} - -function _archive_check() { - # extract hash from name. - local data=($(_archive_parse ${target})) - local saved=${data[2]} - - # calculate actual hash. - local actual=$(pv ${target} | sha1sum | cut -d\ -f1) - - # compare hashes. - [[ "${actual}" = "${saved}" ]] -} - -# complete -o filenames -F _comp_archive_grep archive_check unarchive archive_rm archive_touch -# complete -o filenames -F _comp_archive_grep_fast archive_xz -complete -o filenames -F _comp_archive_name archive_name -complete -o filenames -F _comp_archive_names archive_prune diff --git a/module/common/bash/module/Ask.nix b/module/common/bash/module/Ask.nix new file mode 100644 index 0000000..857b9ce --- /dev/null +++ b/module/common/bash/module/Ask.nix @@ -0,0 +1,28 @@ +{ ... }: { + text = '' + export _ask_model="mistral" + + # Ask general AI. + # Usage: ask + function ask() { + curl http://localhost:11434/api/generate -d "{ + \"model\": \"''${_ask_model}\", + \"prompt\":\"''${*}\" + }" 2> /dev/null | parallel -j1 -- "echo {} | jq -r .response | tr -d '\n'" + echo + } + + # Specify ask model. + function ask_model() { + export _ask_model="''${1}" + } + + function _complete_ask_model() { + local IFS=$'\n' + local models=($(ollama list | sed -e "1d" | cut -f1)) + _autocomplete_first ''${models[@]} + } + + complete -F _complete_ask_model ask_model + ''; +} diff --git a/module/common/bash/module/Ask.sh b/module/common/bash/module/Ask.sh deleted file mode 100644 index 90d475c..0000000 --- a/module/common/bash/module/Ask.sh +++ /dev/null @@ -1,24 +0,0 @@ -export _ask_model="mistral" - -# Ask general AI. -# Usage: ask -function ask() { - curl http://localhost:11434/api/generate -d "{ - \"model\": \"${_ask_model}\", - \"prompt\":\"${*}\" - }" 2> /dev/null | parallel -j1 -- "echo {} | jq -r .response | tr -d '\n'" - echo -} - -# Specify ask model. -function ask_model() { - export _ask_model="${1}" -} - -function _complete_ask_model() { - local IFS=$'\n' - local models=($(ollama list | sed -e "1d" | cut -f1)) - _autocomplete_first ${models[@]} -} - -complete -F _complete_ask_model ask_model diff --git a/module/common/bash/module/Autocomplete.nix b/module/common/bash/module/Autocomplete.nix new file mode 100644 index 0000000..ecf1b12 --- /dev/null +++ b/module/common/bash/module/Autocomplete.nix @@ -0,0 +1,87 @@ +{ ... }: { + text = '' + # Bash autocomplete. + # There are also options like -o nospace. see man for more info. + # Usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo + function _autocomplete() { + local IFS=$'\n' + local commands="''${*}" + + COMPREPLY=() + + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" + + COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) + return 0 + } + + # Autocomplete only first argument. + function _autocomplete_first() { + local IFS=$'\n' + local commands="''${*}" + + COMPREPLY=() + + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" + + if [[ "''${prev}" = "''${command}" ]]; then + COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) + return 0 + fi + } + + # Autocomplete only first argument and the rest with files. + function _autocomplete_first_ls() { + local IFS=$'\n' + local commands="''${*}" + + COMPREPLY=() + + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" + + if [[ "''${prev}" = "''${command}" ]]; then + COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) + return 0 + else + COMPREPLY=( $(compgen -W "$(ls)" -- ''${cur}) ) + return 0 + fi + } + + # Autocomplete by grepping file names. + function _autocomplete_grep() { + local IFS=$'\n' + COMPREPLY=() + + local pattern="''${1}" + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" + + COMPREPLY=( $(compgen -W "$(ls | grep -E ''${pattern})" -- ''${cur}) ) + return 0 + } + + # Autocomplete nested program. + function _autocomplete_nested() { + # local IFS=$'\n' + local cur prev words cword split i + _init_completion -s || return + + for ((i = 1; i <= cword; i++)); do + if [[ ''${words[i]} != -* ]]; then + local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin + local root_command=''${words[i]} + _command_offset ''${i} + return + fi + done + } + ''; +} diff --git a/module/common/bash/module/Autocomplete.sh b/module/common/bash/module/Autocomplete.sh deleted file mode 100644 index a1bc2b9..0000000 --- a/module/common/bash/module/Autocomplete.sh +++ /dev/null @@ -1,83 +0,0 @@ -# Bash autocomplete. -# There are also options like -o nospace. see man for more info. -# Usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo -function _autocomplete() { - local IFS=$'\n' - local commands="${*}" - - COMPREPLY=() - - local cur="${COMP_WORDS[COMP_CWORD]}" - local prev="${COMP_WORDS[COMP_CWORD-1]}" - local command="${COMP_WORDS[0]}" - - COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) - return 0 -} - -# Autocomplete only first argument. -function _autocomplete_first() { - local IFS=$'\n' - local commands="${*}" - - COMPREPLY=() - - local cur="${COMP_WORDS[COMP_CWORD]}" - local prev="${COMP_WORDS[COMP_CWORD-1]}" - local command="${COMP_WORDS[0]}" - - if [[ "${prev}" = "${command}" ]]; then - COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) - return 0 - fi -} - -# Autocomplete only first argument and the rest with files. -function _autocomplete_first_ls() { - local IFS=$'\n' - local commands="${*}" - - COMPREPLY=() - - local cur="${COMP_WORDS[COMP_CWORD]}" - local prev="${COMP_WORDS[COMP_CWORD-1]}" - local command="${COMP_WORDS[0]}" - - if [[ "${prev}" = "${command}" ]]; then - COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) - return 0 - else - COMPREPLY=( $(compgen -W "$(ls)" -- ${cur}) ) - return 0 - fi -} - -# Autocomplete by grepping file names. -function _autocomplete_grep() { - local IFS=$'\n' - COMPREPLY=() - - local pattern="${1}" - local cur="${COMP_WORDS[COMP_CWORD]}" - local prev="${COMP_WORDS[COMP_CWORD-1]}" - local command="${COMP_WORDS[0]}" - - COMPREPLY=( $(compgen -W "$(ls | grep -E ${pattern})" -- ${cur}) ) - return 0 -} - -# Autocomplete nested program. -function _autocomplete_nested() { - # local IFS=$'\n' - local cur prev words cword split i - _init_completion -s || return - - for ((i = 1; i <= cword; i++)); do - if [[ ${words[i]} != -* ]]; then - local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin - local root_command=${words[i]} - _command_offset ${i} - return - fi - done -} diff --git a/module/common/bash/module/Battery.nix b/module/common/bash/module/Battery.nix new file mode 100644 index 0000000..4013582 --- /dev/null +++ b/module/common/bash/module/Battery.nix @@ -0,0 +1,16 @@ +{ ... }: { + text = '' + # Print current battery charge level in percents. + function battery_level() { + head -c -1 /sys/class/power_supply/BAT*/capacity + echo '%' + } + + # Get battery's info. + function battery_info() { + local IFS=$'\n' + local battery=("$(upower --enumerate | grep battery_BAT)") + upower -i "''${battery[0]}" + } + ''; +} diff --git a/module/common/bash/module/Battery.sh b/module/common/bash/module/Battery.sh deleted file mode 100644 index 8d1b799..0000000 --- a/module/common/bash/module/Battery.sh +++ /dev/null @@ -1,12 +0,0 @@ -# Print current battery charge in percents. -function battery_charge() { - head -c -1 /sys/class/power_supply/BAT*/capacity - echo '%' -} - -# Get battery's info. -function battery_info() { - local IFS=$'\n' - local battery=("$(upower --enumerate | grep battery_BAT)") - upower -i "${battery[0]}" -} diff --git a/module/common/bash/module/Bootstrap.nix b/module/common/bash/module/Bootstrap.nix new file mode 100644 index 0000000..f082712 --- /dev/null +++ b/module/common/bash/module/Bootstrap.nix @@ -0,0 +1,45 @@ +{ ... }: { + text = '' + # Install nixos to specified drive. To be run from Live ISO. + # Usage: bootstrap_nixos [HOST] + function bootstrap_nixos() { + local target="''${1}" + local host="''${2}" + + if [[ "''${target}" = "" ]]; then + help bootstrap_nixos + return 2 + fi + + # Create partitions. + parted -s "''${target}" mktable gpt + parted -s "''${target}" mkpart primary 0% 512MB + parted -s "''${target}" mkpart primary 512MB 100% + parted -s "''${target}" name 1 NIXBOOT + parted -s "''${target}" name 2 NIXROOT + parted -s "''${target}" set 1 esp on + + # Format. + mkfs.fat -F 32 /dev/disk/by-partlabel/NIXBOOT + mkfs.ext4 -F /dev/disk/by-partlabel/NIXROOT + + # Mount. + mount /dev/disk/by-partlabel/NIXROOT /mnt + mkdir /mnt/boot + mount /dev/disk/by-partlabel/NIXBOOT /mnt/boot + + # Generate config. + nixos-generate-config --root /mnt + + # Install. + cd /mnt + if [[ "''${host}" = "" ]]; then + _warn "Warning: Installing basic system." + nixos-install + else + _info "Installing ''${host}..." + nixos-install --no-root-password --no-channel-copy --flake "''${_nix_system_config}#''${host}" + fi + } + ''; +} diff --git a/module/common/bash/module/Bootstrap.sh b/module/common/bash/module/Bootstrap.sh deleted file mode 100644 index b35c8c8..0000000 --- a/module/common/bash/module/Bootstrap.sh +++ /dev/null @@ -1,70 +0,0 @@ -# Install Editorconfig file (with tabs) in current directory. -function bootstrap_editorconfig() { - echo "\ -[*] -end_of_line = lf -charset = utf-8 -indent_style = tab -insert_final_newline = true -trim_trailing_whitespace = true -" > .editorconfig -} - -# Install Editorconfig file (with specified spaces, 8 by default) in current directory. -# Usage: bootstrap_editorconfig_space [AMOUNT] -function bootstrap_editorconfig_space() { - local spaces="${1}" - [[ "${spaces}" = "" ]] && spaces=8 - - echo "\ -[*] -end_of_line = lf -charset = utf-8 -indent_style = space -indent_size = ${spaces} -insert_final_newline = true -trim_trailing_whitespace = true -" > .editorconfig -} - -# Install nixos to specified drive. To be run from Live ISO. -# Usage: bootstrap_nixos [HOST] -function bootstrap_nixos() { - local target="${1}" - local host="${2}" - - if [[ "${target}" = "" ]]; then - help bootstrap_nixos - return 2 - fi - - # Create partitions. - parted -s "${target}" mktable gpt - parted -s "${target}" mkpart primary 0% 512MB - parted -s "${target}" mkpart primary 512MB 100% - parted -s "${target}" name 1 NIXBOOT - parted -s "${target}" name 2 NIXROOT - parted -s "${target}" set 1 esp on - - # Format. - mkfs.fat -F 32 /dev/disk/by-partlabel/NIXBOOT - mkfs.ext4 -F /dev/disk/by-partlabel/NIXROOT - - # Mount. - mount /dev/disk/by-partlabel/NIXROOT /mnt - mkdir /mnt/boot - mount /dev/disk/by-partlabel/NIXBOOT /mnt/boot - - # Generate config. - nixos-generate-config --root /mnt - - # Install. - cd /mnt - if [[ "${host}" = "" ]]; then - _warn "Warning: Installing basic system." - nixos-install - else - _info "Installing ${host}..." - nixos-install --no-root-password --no-channel-copy --flake "${_nix_system_config}#${host}" - fi -} diff --git a/module/common/bash/module/Brightness.nix b/module/common/bash/module/Brightness.nix new file mode 100644 index 0000000..e681f27 --- /dev/null +++ b/module/common/bash/module/Brightness.nix @@ -0,0 +1,22 @@ +{ ... }: { + text = '' + # Set display brightness to a minimum. + function brmin() { + light -S 0.01 + } + + # Set display brightness to a maximum. + function brmax() { + light -S 100 + } + + # Set display brightness in percent, 50% default. + # Usage: brset [LEVEL] + function brset() { + local level=''${1} + [[ "''${level}" = "" ]] && level=50 + + light -S ''${level} + } + ''; +} diff --git a/module/common/bash/module/Brightness.sh b/module/common/bash/module/Brightness.sh deleted file mode 100644 index e9c2948..0000000 --- a/module/common/bash/module/Brightness.sh +++ /dev/null @@ -1,18 +0,0 @@ -# Set display brightness to a minimum. -function brmin() { - light -S 0.01 -} - -# Set display brightness to a maximum. -function brmax() { - light -S 100 -} - -# Set display brightness in percent, 50% default. -# Usage: brset [LEVEL] -function brset() { - local level=${1} - [[ "${level}" = "" ]] && level=50 - - light -S ${level} -} diff --git a/module/common/bash/module/Cd.nix b/module/common/bash/module/Cd.nix new file mode 100644 index 0000000..1be1553 --- /dev/null +++ b/module/common/bash/module/Cd.nix @@ -0,0 +1,63 @@ +{ ... }: { + text = '' + # CD (back to) directory. + # Goes to the exact-match dir first. If no exact match found, it finds first directory that contains the input (case-insensitive). + # Usage: cdd + function cdd() { + local target="''${1}" + + if [[ "''${target}" = "" ]]; then + help cdd + return 2 + fi + + local array=($(_cdd_directories)) + local result + + # Check for exact match ELSE look for containing. + if _contains ''${target} ''${array[@]}; then + local current="''${PWD%/*}" + result="''${current%\/$target\/*}/''${target}" + else + # Make search case-insensitive. + shopt -s nocasematch + + # Find dir name that contains input. + local found=1 + for (( idx=''${#array[@]}-1 ; idx>=0 ; idx-- )); do + dir="''${array[idx]}" + [[ "''${dir}" =~ "''${target}" ]] && found=0 + [[ ''${found} = 0 ]] && result="/''${dir}''${result}" + done + + # Clean-up??? + shopt -u nocasematch + fi + + # Go there! + if [[ "''${result}" != "" ]]; then + echo "''${result}" + cd "''${result}" + else + return 1 + fi + } + + # Get list of all parent dirs. + function _cdd_directories() { + local array + IFS='/' read -r -a array <<< "''${PWD}" + array=("''${array[@]:1}") + unset array[-1] + printf "%s\n" "''${array[@]}" + } + + function _comp_cdd() { + local IFS=$'\n' + local dirs=($(_cdd_directories)) + _autocomplete_first ''${dirs[@]} + } + + complete -o nosort -o filenames -F _comp_cdd cdd + ''; +} diff --git a/module/common/bash/module/Cd.sh b/module/common/bash/module/Cd.sh deleted file mode 100644 index 805afb4..0000000 --- a/module/common/bash/module/Cd.sh +++ /dev/null @@ -1,59 +0,0 @@ -# CD (back to) directory. -# Goes to the exact-match dir first. If no exact match found, it finds first directory that contains the input (case-insensitive). -# Usage: cdd -function cdd() { - local target="${1}" - - if [[ "${target}" = "" ]]; then - help cdd - return 2 - fi - - local array=($(_cdd_directories)) - local result - - # Check for exact match ELSE look for containing. - if _contains ${target} ${array[@]}; then - local current="${PWD%/*}" - result="${current%\/$target\/*}/${target}" - else - # Make search case-insensitive. - shopt -s nocasematch - - # Find dir name that contains input. - local found=1 - for (( idx=${#array[@]}-1 ; idx>=0 ; idx-- )); do - dir="${array[idx]}" - [[ "${dir}" =~ "${target}" ]] && found=0 - [[ ${found} = 0 ]] && result="/${dir}${result}" - done - - # Clean-up??? - shopt -u nocasematch - fi - - # Go there! - if [[ "${result}" != "" ]]; then - echo "${result}" - cd "${result}" - else - return 1 - fi -} - -# Get list of all parent dirs. -function _cdd_directories() { - local array - IFS='/' read -r -a array <<< "${PWD}" - array=("${array[@]:1}") - unset array[-1] - printf "%s\n" "${array[@]}" -} - -function _comp_cdd() { - local IFS=$'\n' - local dirs=($(_cdd_directories)) - _autocomplete_first ${dirs[@]} -} - -complete -o nosort -o filenames -F _comp_cdd cdd diff --git a/module/common/bash/module/Checksum.nix b/module/common/bash/module/Checksum.nix new file mode 100644 index 0000000..9b31962 --- /dev/null +++ b/module/common/bash/module/Checksum.nix @@ -0,0 +1,87 @@ +{ ... }: { + text = '' + # Save file checksums. + # For file with a name `file` it will create a new file called `.file.sha1` with hash in it. + # All files by default. + # Usage: checksum_create [FILES] + function checksum_create() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + process() { + local hashfile=".''${target#./}.sha1" + + # Skip if hash exists. + [[ -f "''${hashfile}" ]] && return 0 + + # Calculate hash. + pv ''${target} | sha1sum > ''${hashfile} + } + + _iterate_targets process ''${targets[@]} + } + + # Check stored values against actual files. + # All files by default. + # Usage: checksum_check [FILES] + function checksum_check() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + process() { + local hashfile=".''${target#./}.sha1" + + # Skip if hash doesn't exist. + [[ -f "''${hashfile}" ]] || { _iterate_skip "No hash found."; return 0; } + + # Calculate hash. + local stored=$(cat "''${hashfile}" | cut -d\ -f1) + local actual=$(pv "''${target}" | sha1sum | cut -d\ -f1) + + if [[ "''${stored}" != "''${actual}" ]]; then + _error "Failed." + return 1 + fi + } + + _iterate_targets process ''${targets[@]} + } + + # Calculate hashes for all files recursively and store in a file called `checksum.sha1`. + function checksum() { + find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1 + } + + # Create checksum for a file. + # Usage: _checksum_create + function _checksum_create() { + local path="''${1%/*}" + local name="''${1##*/}" + sha1sum "''${path}/''${name}" > "''${path}/.''${name}.sha1" + } + + # Check checksum for a file. + # Usage: _checksum_check + function _checksum_check() { + local file="''${1##*\ \ }" + local stored="''${1%%\ \ *}" + + # Skip if no file. + [[ -f "''${file}" ]] || return 0 + + # Check file hash. + local actual=$(sha1sum "''${file}") + actual="''${actual%%\ \ *}" + + # Compare values. + if [[ "''${stored}" != "''${actual}" ]]; then + _error "''${file}: Failed." + return 1 + fi + + return 0 + } + ''; +} diff --git a/module/common/bash/module/Checksum.sh b/module/common/bash/module/Checksum.sh deleted file mode 100644 index 725d571..0000000 --- a/module/common/bash/module/Checksum.sh +++ /dev/null @@ -1,83 +0,0 @@ -# Save file checksums. -# For file with a name `file` it will create a new file called `.file.sha1` with hash in it. -# All files by default. -# Usage: checksum_create [FILES] -function checksum_create() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - process() { - local hashfile=".${target#./}.sha1" - - # Skip if hash exists. - [[ -f "${hashfile}" ]] && return 0 - - # Calculate hash. - pv ${target} | sha1sum > ${hashfile} - } - - _iterate_targets process ${targets[@]} -} - -# Check stored values against actual files. -# All files by default. -# Usage: checksum_check [FILES] -function checksum_check() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - process() { - local hashfile=".${target#./}.sha1" - - # Skip if hash doesn't exist. - [[ -f "${hashfile}" ]] || { _iterate_skip "No hash found."; return 0; } - - # Calculate hash. - local stored=$(cat "${hashfile}" | cut -d\ -f1) - local actual=$(pv "${target}" | sha1sum | cut -d\ -f1) - - if [[ "${stored}" != "${actual}" ]]; then - _error "Failed." - return 1 - fi - } - - _iterate_targets process ${targets[@]} -} - -# Calculate hashes for all files recursively and store in a file called `checksum.sha1`. -function checksum() { - find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1 -} - -# Create checksum for a file. -# Usage: _checksum_create -function _checksum_create() { - local path="${1%/*}" - local name="${1##*/}" - sha1sum "${path}/${name}" > "${path}/.${name}.sha1" -} - -# Check checksum for a file. -# Usage: _checksum_check -function _checksum_check() { - local file="${1##*\ \ }" - local stored="${1%%\ \ *}" - - # Skip if no file. - [[ -f "${file}" ]] || return 0 - - # Check file hash. - local actual=$(sha1sum "${file}") - actual="${actual%%\ \ *}" - - # Compare values. - if [[ "${stored}" != "${actual}" ]]; then - _error "${file}: Failed." - return 1 - fi - - return 0 -} diff --git a/module/common/bash/module/Chmod.nix b/module/common/bash/module/Chmod.nix new file mode 100644 index 0000000..9d4153c --- /dev/null +++ b/module/common/bash/module/Chmod.nix @@ -0,0 +1,9 @@ +{ ... }: { + text = '' + # Add executable flag to file. + # Usage: x + function x() { + chmod +x -- "''${@}" + } + ''; +} diff --git a/module/common/bash/module/Chmod.sh b/module/common/bash/module/Chmod.sh deleted file mode 100644 index 1580af6..0000000 --- a/module/common/bash/module/Chmod.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Add executable flag to file. -# Usage: x -function x() { - chmod +x -- "${@}" -} diff --git a/module/common/bash/module/Color.nix b/module/common/bash/module/Color.nix new file mode 100644 index 0000000..48b4c2c --- /dev/null +++ b/module/common/bash/module/Color.nix @@ -0,0 +1,28 @@ +{ ... }: { + text = '' + # Collection of available CLI colors. + # They may differ depending on the terminal used. + # Colors with 'b' prefix are bold colors. + + export color_default="\033[0m" + export color_blue="\033[0;34m" + export color_bblue="\033[1;34m" + export color_cyan="\033[0;36m" + export color_bcyan="\033[1;36m" + export color_green="\033[0;32m" + export color_bgreen="\033[1;32m" + export color_purple="\033[0;35m" + export color_bpurple="\033[1;35m" + export color_red="\033[0;31m" + export color_bred="\033[1;31m" + export color_white="\033[0;37m" + export color_bwhite="\033[1;37m" + export color_yellow="\033[0;33m" + export color_byellow="\033[1;33m" + + # Print all available colors with their names colored in corresponding color. + function color_test() { + echo -e "''${color_default}color_default\n''${color_blue}color_blue\n''${color_bblue}color_bblue\n''${color_cyan}color_cyan\n''${color_bcyan}color_bcyan\n''${color_green}color_green\n''${color_bgreen}color_bgreen\n''${color_purple}color_purple\n''${color_bpurple}color_bpurple\n''${color_red}color_red\n''${color_bred}color_bred\n''${color_white}color_white\n''${color_bwhite}color_bwhite\n''${color_yellow}color_yellow\n''${color_byellow}color_byellow" + } + ''; +} diff --git a/module/common/bash/module/Color.sh b/module/common/bash/module/Color.sh deleted file mode 100644 index 4596d82..0000000 --- a/module/common/bash/module/Color.sh +++ /dev/null @@ -1,24 +0,0 @@ -# Collection of available CLI colors. -# They may differ depending on the terminal used. -# Colors with 'b' prefix are bold colors. - -export color_default="\033[0m" -export color_blue="\033[0;34m" -export color_bblue="\033[1;34m" -export color_cyan="\033[0;36m" -export color_bcyan="\033[1;36m" -export color_green="\033[0;32m" -export color_bgreen="\033[1;32m" -export color_purple="\033[0;35m" -export color_bpurple="\033[1;35m" -export color_red="\033[0;31m" -export color_bred="\033[1;31m" -export color_white="\033[0;37m" -export color_bwhite="\033[1;37m" -export color_yellow="\033[0;33m" -export color_byellow="\033[1;33m" - -# Print all available colors with their names colored in corresponding color. -function color_test() { - echo -e "${color_default}color_default\n${color_blue}color_blue\n${color_bblue}color_bblue\n${color_cyan}color_cyan\n${color_bcyan}color_bcyan\n${color_green}color_green\n${color_bgreen}color_bgreen\n${color_purple}color_purple\n${color_bpurple}color_bpurple\n${color_red}color_red\n${color_bred}color_bred\n${color_white}color_white\n${color_bwhite}color_bwhite\n${color_yellow}color_yellow\n${color_byellow}color_byellow" -} diff --git a/module/common/bash/module/Container.nix b/module/common/bash/module/Container.nix new file mode 100644 index 0000000..641998d --- /dev/null +++ b/module/common/bash/module/Container.nix @@ -0,0 +1,84 @@ +{ ... }: { + text = '' + # Attach/create container box in current directory with specified name. + # By default uses current dir name. + # Usage: ca [NAME] + function ca() { + local name="''${1}" + + # Set default name. + # [[ "''${name}" = "" ]] && name="main" + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + + # Append box prefix. + name="box-''${name}" + + # Create container. + docker run \ + --privileged \ + -d -it \ + -h "''${HOSTNAME}''${name#box}" --name "''${name}" \ + --workdir /data \ + -e XDG_RUNTIME_DIR=/tmp \ + -e WAYLAND_DISPLAY=''${WAYLAND_DISPLAY} \ + -v ''${XDG_RUNTIME_DIR}/''${WAYLAND_DISPLAY}:/tmp/''${WAYLAND_DISPLAY} \ + -v ''${PWD}:/data \ + -v ''${HOME}:/root \ + debian:latest bash -c bash &> /dev/null + + # Attempt to start container. + docker start "''${name}" &> /dev/null + + # Attach to running container. + docker attach "''${name}" + } + + # Remove container box with specified name. + # By default uses current dir name. + # Usage: ck [NAME] + function ck() { + local name="''${1}" + + # Set default name. + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + + # Append box prefix. + name="box-''${name}" + + # Kill container. + docker kill "''${name}" &> /dev/null + docker rm "''${name}" &> /dev/null + } + + # Remove all container boxes. + function cka() { + local IFS=$'\n' + local boxes=$(_get_boxes) + + for box in ''${boxes[@]}; do + ck "''${box}" + done + } + + # List all container boxes. + function cl() { + _get_boxes + } + + # Print all boxes. + function _get_boxes() { + local IFS=$'\n' + local boxes=$(docker ps -a | grep "box-" | sed -e "s/.*box-//") + + [[ "''${boxes[@]}" != "" ]] && echo "''${boxes[@]}" || true + } + + # Autocomplete with boxes. + function _comp_get_boxes() { + local IFS=$'\n' + _autocomplete_first $(_get_boxes) + } + + complete -F _comp_get_boxes ca ck + ''; +} diff --git a/module/common/bash/module/Container.sh b/module/common/bash/module/Container.sh deleted file mode 100644 index 7241ab8..0000000 --- a/module/common/bash/module/Container.sh +++ /dev/null @@ -1,80 +0,0 @@ -# Attach/create container box in current directory with specified name. -# By default uses current dir name. -# Usage: ca [NAME] -function ca() { - local name="${1}" - - # Set default name. - # [[ "${name}" = "" ]] && name="main" - [[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}") - - # Append box prefix. - name="box-${name}" - - # Create container. - docker run \ - --privileged \ - -d -it \ - -h "${HOSTNAME}${name#box}" --name "${name}" \ - --workdir /data \ - -e XDG_RUNTIME_DIR=/tmp \ - -e WAYLAND_DISPLAY=${WAYLAND_DISPLAY} \ - -v ${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}:/tmp/${WAYLAND_DISPLAY} \ - -v ${PWD}:/data \ - -v ${HOME}:/root \ - debian:latest bash -c bash &> /dev/null - - # Attempt to start container. - docker start "${name}" &> /dev/null - - # Attach to running container. - docker attach "${name}" -} - -# Remove container box with specified name. -# By default uses current dir name. -# Usage: ck [NAME] -function ck() { - local name="${1}" - - # Set default name. - [[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}") - - # Append box prefix. - name="box-${name}" - - # Kill container. - docker kill "${name}" &> /dev/null - docker rm "${name}" &> /dev/null -} - -# Remove all container boxes. -function cka() { - local IFS=$'\n' - local boxes=$(_get_boxes) - - for box in ${boxes[@]}; do - ck "${box}" - done -} - -# List all container boxes. -function cl() { - _get_boxes -} - -# Print all boxes. -function _get_boxes() { - local IFS=$'\n' - local boxes=$(docker ps -a | grep "box-" | sed -e "s/.*box-//") - - [[ "${boxes[@]}" != "" ]] && echo "${boxes[@]}" || true -} - -# Autocomplete with boxes. -function _comp_get_boxes() { - local IFS=$'\n' - _autocomplete_first $(_get_boxes) -} - -complete -F _comp_get_boxes ca ck diff --git a/module/common/bash/module/Copypaste.nix b/module/common/bash/module/Copypaste.nix new file mode 100644 index 0000000..62400e6 --- /dev/null +++ b/module/common/bash/module/Copypaste.nix @@ -0,0 +1,13 @@ +{ ... }: { + text = '' + # Copy stdin to system clipboard. *Example:* `echo hi \| copy`. + function copy() { + wl-copy + } + + # Paste system clipboard to stdout. *Example:* `paste > file.txt`. + function paste() { + wl-paste + } + ''; +} diff --git a/module/common/bash/module/Copypaste.sh b/module/common/bash/module/Copypaste.sh deleted file mode 100644 index db691cf..0000000 --- a/module/common/bash/module/Copypaste.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Copy stdin to system clipboard. *Example:* `echo hi \| copy`. -function copy() { - wl-copy -} - -# Paste system clipboard to stdout. *Example:* `paste > file.txt`. -function paste() { - wl-paste -} diff --git a/module/common/bash/module/Cp.nix b/module/common/bash/module/Cp.nix new file mode 100644 index 0000000..f327cb4 --- /dev/null +++ b/module/common/bash/module/Cp.nix @@ -0,0 +1,28 @@ +{ ... }: { + text = '' + # Replaces default cp with rsync. + # Usage: rcp + function rcp() { + rsync -ahP --chmod=u+w "''${@}" + } + + # Copy and also merge all changes (delete dst files that do not exist in src). + # Usage: rcp_merge + function rcp_merge() { + rsync -ahP --chmod=u+w --delete "''${@}" + } + + # Copy by creating hardlinks. + # Works for directories, too. + # Usage: cp_link + function cp_link() { + /usr/bin/env cp -lr "''${@}" + } + + # Print output of cp_merge without writing anything. + # Usage: rcp_test + function rcp_test() { + rsync -ahP --chmod=u+w --delete -n "''${@}" + } + ''; +} diff --git a/module/common/bash/module/Cp.sh b/module/common/bash/module/Cp.sh deleted file mode 100644 index 87ccc31..0000000 --- a/module/common/bash/module/Cp.sh +++ /dev/null @@ -1,24 +0,0 @@ -# Replaces default cp with rsync. -# Usage: rcp -function rcp() { - rsync -ahP --chmod=u+w "${@}" -} - -# Copy and also merge all changes (delete dst files that do not exist in src). -# Usage: rcp_merge -function rcp_merge() { - rsync -ahP --chmod=u+w --delete "${@}" -} - -# Copy by creating hardlinks. -# Works for directories, too. -# Usage: cp_link -function cp_link() { - /usr/bin/env cp -lr "${@}" -} - -# Print output of cp_merge without writing anything. -# Usage: rcp_test -function rcp_test() { - rsync -ahP --chmod=u+w --delete -n "${@}" -} diff --git a/module/common/bash/module/Date.nix b/module/common/bash/module/Date.nix new file mode 100644 index 0000000..5fb42f5 --- /dev/null +++ b/module/common/bash/module/Date.nix @@ -0,0 +1,13 @@ +{ ... }: { +text = '' + # Print today date in yyyyMMdd format. + function today() { + date +%Y%m%d + } + + # Current day of week number. + function dow() { + date +%u + } +''; +} diff --git a/module/common/bash/module/Date.sh b/module/common/bash/module/Date.sh deleted file mode 100644 index 45ff32f..0000000 --- a/module/common/bash/module/Date.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Print today date in yyyyMMdd format. -function today() { - date +%Y%m%d -} - -# Current day of week number. -function dow() { - date +%u -} diff --git a/module/common/bash/module/Dconf.nix b/module/common/bash/module/Dconf.nix new file mode 100644 index 0000000..9975d73 --- /dev/null +++ b/module/common/bash/module/Dconf.nix @@ -0,0 +1,20 @@ +{ ... }: { + text = '' + export _gdconf_path="''${HOME}/.config/linux/Gnome.dconf" + + # Load Gnome settings. + function dconf_load() { + sed -i -e s/voronind/$(whoami)/g ''${_gdconf_path} ; dconf load / < ''${_gdconf_path} + } + + # Dump Gnome settings into the file. + # Default name is `gnome.dconf`. + # Do this before changing settings and after, an then run `diff` to find out what to add to the main `gnome.dconf`. + # Usage: dconf_save [FILE] + function dconf_save() { + local name="''${1}" + [[ "''${name}" = "" ]] && name="gnome.dconf" + dconf dump / > "''${name}" + } + ''; +} diff --git a/module/common/bash/module/Dconf.sh b/module/common/bash/module/Dconf.sh deleted file mode 100644 index 338731f..0000000 --- a/module/common/bash/module/Dconf.sh +++ /dev/null @@ -1,16 +0,0 @@ -export _gdconf_path="${HOME}/.config/linux/Gnome.dconf" - -# Load Gnome settings. -function dconf_load() { - sed -i -e s/voronind/$(whoami)/g ${_gdconf_path} ; dconf load / < ${_gdconf_path} -} - -# Dump Gnome settings into the file. -# Default name is `gnome.dconf`. -# Do this before changing settings and after, an then run `diff` to find out what to add to the main `gnome.dconf`. -# Usage: dconf_save [FILE] -function dconf_save() { - local name="${1}" - [[ "${name}" = "" ]] && name="gnome.dconf" - dconf dump / > "${name}" -} diff --git a/module/common/bash/module/Disk.nix b/module/common/bash/module/Disk.nix new file mode 100644 index 0000000..e1f668d --- /dev/null +++ b/module/common/bash/module/Disk.nix @@ -0,0 +1,15 @@ +{ ... }: { + text = '' + # Show only physical drives info. + function pdf() { + df --si | sed -e '1p' -e '/^\/dev\//!d' + } + + # Show total size in SI. + # Current dir by default. + # Usage: tdu [DIRS] + function tdu() { + du -sh --si "''${@}" + } + ''; +} diff --git a/module/common/bash/module/Disk.sh b/module/common/bash/module/Disk.sh deleted file mode 100644 index 2e78cc2..0000000 --- a/module/common/bash/module/Disk.sh +++ /dev/null @@ -1,11 +0,0 @@ -# Show only physical drives info. -function pdf() { - df --si | sed -e '1p' -e '/^\/dev\//!d' -} - -# Show total size in SI. -# Current dir by default. -# Usage: tdu [DIRS] -function tdu() { - du -sh --si "${@}" -} diff --git a/module/common/bash/module/Distrobox.nix b/module/common/bash/module/Distrobox.nix new file mode 100644 index 0000000..0b28206 --- /dev/null +++ b/module/common/bash/module/Distrobox.nix @@ -0,0 +1,19 @@ +{ ... }: { + text = '' + # Create/Attach to the box. + # Uses name `main` by default. + # Usage: da [BOX] + function da() { + local name="''${1}" + + [[ "''${name}" = "" ]] && name="main" + # if [[ "''${name}" = "" ]]; then + # help da + # return 2 + # fi + + # --user 0 is required for rootless docker. + distrobox enter -a '--user=0' "''${name}" + } + ''; +} diff --git a/module/common/bash/module/Distrobox.sh b/module/common/bash/module/Distrobox.sh deleted file mode 100644 index 9e3bc8d..0000000 --- a/module/common/bash/module/Distrobox.sh +++ /dev/null @@ -1,15 +0,0 @@ -# Create/Attach to the box. -# Uses name `main` by default. -# Usage: da [BOX] -function da() { - local name="${1}" - - [[ "${name}" = "" ]] && name="main" - # if [[ "${name}" = "" ]]; then - # help da - # return 2 - # fi - - # --user 0 is required for rootless docker. - distrobox enter -a '--user=0' "${name}" -} diff --git a/module/common/bash/module/Dmenu.nix b/module/common/bash/module/Dmenu.nix new file mode 100644 index 0000000..bcdf1b5 --- /dev/null +++ b/module/common/bash/module/Dmenu.nix @@ -0,0 +1,15 @@ +{ ... }: { + text = '' + # Wrapped dmenu_path to include my functions. + function _dmenu_path_wrapped() { + c=0 + while [ ''${c} -lt 1000 ]; do + echo + ((c++)) + done + + dmenu_path + find_function | grep -v ^_ + } + ''; +} diff --git a/module/common/bash/module/Dmenu.sh b/module/common/bash/module/Dmenu.sh deleted file mode 100644 index c94d7dc..0000000 --- a/module/common/bash/module/Dmenu.sh +++ /dev/null @@ -1,11 +0,0 @@ -# Wrapped dmenu_path to include my functions. -function _dmenu_path_wrapped() { - c=0 - while [ ${c} -lt 1000 ]; do - echo - ((c++)) - done - - dmenu_path - find_function | grep -v ^_ -} diff --git a/module/common/bash/module/Docker.nix b/module/common/bash/module/Docker.nix new file mode 100644 index 0000000..2febc60 --- /dev/null +++ b/module/common/bash/module/Docker.nix @@ -0,0 +1,99 @@ +{ ... }: { + text = '' + # Show container's volumes. + # Usage: docker_volumes + function docker_volumes() { + docker inspect -f '{{ .Mounts }}' "''${@}" + } + + # Check if any container exited. + function docker_health() { + docker ps -a | grep Exited + } + + # Find out container's IP address. + # Usage: docker_ip + function docker_ip() { + docker inspect -f '\'''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' "''${1}" | sed "s/^.//" | sed "s/.$//" + } + + # Update all docker images. + function docker_update() { + docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull + } + + # Docker compose shortcut. + function dc() { + docker compose "''${@}" + } + + # Docker compose up. + # Usage: dcu [SERVICES] + function dcu() { + docker compose up -d "''${@}" + } + + # Docker compose down. + # Usage: dcd [SERVICES] + function dcd() { + docker compose down "''${@}" + } + + # Docker compose pull. + # Usage: dcp [SERVICES] + function dcp() { + docker compose pull "''${@}" + } + + # Docker compose logs. + # Usage: dcl [SERVICES] + function dcl() { + docker compose logs -f "''${@}" + } + + # Docker compose restart. + # Usage: dcr [SERVICES] + function dcr() { + docker compose restart "''${@}" + } + + # Docker compose stop. + # Usage: dcs [SERVICES] + function dcs() { + docker compose stop "''${@}" + } + + # Docker compose down & up specified services. + # Usage: dcdu [SERVICES] + function dcdu() { + dcd "''${@}" + dcu "''${@}" + } + + # Docker compose pull & up specified services. + # Usage: dcpu [SERVICES] + function dcpu() { + dcp "''${@}" + dcu "''${@}" + } + + # Docker compose up & attach to logs for specified services. + # Usage: dcul [SERVICES] + function dcul() { + dcu "''${@}" && dcl "''${@}" + } + + # Autocomplete with available services. + function _dc_services() { + _autocomplete "$(docker compose config --services 2> /dev/null)" + } + + # Autocomplete with available container names. + function _dc_containers() { + _autocomplete "$(docker ps --format "\""{{.Names}}"\"")" + } + + complete -F _dc_services dcu dcd dcp dcl dcul dcdu dcr dcs dcpu + complete -F _dc_containers docker_volumes docker_ip + ''; +} diff --git a/module/common/bash/module/Docker.sh b/module/common/bash/module/Docker.sh deleted file mode 100644 index f5bc8fa..0000000 --- a/module/common/bash/module/Docker.sh +++ /dev/null @@ -1,95 +0,0 @@ -# Show container's volumes. -# Usage: docker_volumes -function docker_volumes() { - docker inspect -f '{{ .Mounts }}' "${@}" -} - -# Check if any container exited. -function docker_health() { - docker ps -a | grep Exited -} - -# Find out container's IP address. -# Usage: docker_ip -function docker_ip() { - docker inspect -f '\''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' "${1}" | sed "s/^.//" | sed "s/.$//" -} - -# Update all docker images. -function docker_update() { - docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull -} - -# Docker compose shortcut. -function dc() { - docker compose "${@}" -} - -# Docker compose up. -# Usage: dcu [SERVICES] -function dcu() { - docker compose up -d "${@}" -} - -# Docker compose down. -# Usage: dcd [SERVICES] -function dcd() { - docker compose down "${@}" -} - -# Docker compose pull. -# Usage: dcp [SERVICES] -function dcp() { - docker compose pull "${@}" -} - -# Docker compose logs. -# Usage: dcl [SERVICES] -function dcl() { - docker compose logs -f "${@}" -} - -# Docker compose restart. -# Usage: dcr [SERVICES] -function dcr() { - docker compose restart "${@}" -} - -# Docker compose stop. -# Usage: dcs [SERVICES] -function dcs() { - docker compose stop "${@}" -} - -# Docker compose down & up specified services. -# Usage: dcdu [SERVICES] -function dcdu() { - dcd "${@}" - dcu "${@}" -} - -# Docker compose pull & up specified services. -# Usage: dcpu [SERVICES] -function dcpu() { - dcp "${@}" - dcu "${@}" -} - -# Docker compose up & attach to logs for specified services. -# Usage: dcul [SERVICES] -function dcul() { - dcu "${@}" && dcl "${@}" -} - -# Autocomplete with available services. -function _dc_services() { - _autocomplete "$(docker compose config --services 2> /dev/null)" -} - -# Autocomplete with available container names. -function _dc_containers() { - _autocomplete "$(docker ps --format "\""{{.Names}}"\"")" -} - -complete -F _dc_services dcu dcd dcp dcl dcul dcdu dcr dcs dcpu -complete -F _dc_containers docker_volumes docker_ip diff --git a/module/common/bash/module/Dvd.nix b/module/common/bash/module/Dvd.nix new file mode 100644 index 0000000..24a9d9b --- /dev/null +++ b/module/common/bash/module/Dvd.nix @@ -0,0 +1,43 @@ +{ ... }: { + text = '' + # Burn specified iso file to DVD. + # Usage: dvd_burn_iso + function dvd_burn_iso() { + local iso="''${1}" + if [[ "''${iso}" = "" ]]; then + help dvd_burn_iso + return 2 + fi + + growisofs -dvd-compat -speed=8 -use-the-force-luke=tty -Z /dev/sr0="''${iso}" + } + + # Burn specified iso file to CD. + # Usage: cd_burn_iso + function cd_burn_iso() { + local iso="''${1}" + if [[ "''${iso}" = "" ]]; then + help cd_burn_iso + return 2 + fi + + wodim speed=8 -tao dev=/dev/sr0 "''${iso}" + } + + # Burn specified audio files to CD. + # Usage: cd_burn_audio + function cd_burn_audio() { + if [[ "''${*}" = "" ]]; then + help cd_burn_audio + return 2 + fi + + cdrecord -v dev=/dev/sr0 speed=8 -audio -pad "''${*}" + } + + # Spawn Nix shell with required tools. + function dvd_shell() { + NIX_SHELL="dvd" tmpshell dvdplusrwtools cdrkit + } + ''; +} diff --git a/module/common/bash/module/Dvd.sh b/module/common/bash/module/Dvd.sh deleted file mode 100644 index 2afd1b3..0000000 --- a/module/common/bash/module/Dvd.sh +++ /dev/null @@ -1,39 +0,0 @@ -# Burn specified iso file to DVD. -# Usage: dvd_burn_iso -function dvd_burn_iso() { - local iso="${1}" - if [[ "${iso}" = "" ]]; then - help dvd_burn_iso - return 2 - fi - - growisofs -dvd-compat -speed=8 -use-the-force-luke=tty -Z /dev/sr0="${iso}" -} - -# Burn specified iso file to CD. -# Usage: cd_burn_iso -function cd_burn_iso() { - local iso="${1}" - if [[ "${iso}" = "" ]]; then - help cd_burn_iso - return 2 - fi - - wodim speed=8 -tao dev=/dev/sr0 "${iso}" -} - -# Burn specified audio files to CD. -# Usage: cd_burn_audio -function cd_burn_audio() { - if [[ "${*}" = "" ]]; then - help cd_burn_audio - return 2 - fi - - cdrecord -v dev=/dev/sr0 speed=8 -audio -pad "${*}" -} - -# Spawn Nix shell with required tools. -function dvd_shell() { - NIX_SHELL="dvd" tmpshell dvdplusrwtools cdrkit -} diff --git a/module/common/bash/module/Ffmpeg.nix b/module/common/bash/module/Ffmpeg.nix new file mode 100644 index 0000000..cfbec45 --- /dev/null +++ b/module/common/bash/module/Ffmpeg.nix @@ -0,0 +1,99 @@ +{ ... }: { + text = '' + # Mux audio into containers. File names in sound and current dirrectories must match. + # Usage: ffmpeg_mux_audio + function ffmpeg_mux_audio() { + if [[ "''${1}" = "" ]]; then + help ffmpeg_mux_audio + return 2 + fi + + for file in *; do ffmpeg -i "$file" -i "$1"/"$file" -c copy -map 0:v:0 -map 1:a:0 -shortest "$2"/"$file"; done + } + + # Mux cover into music file. + # Usage: ffmpeg_mux_cover + function ffmpeg_mux_cover() { + if [[ "''${1}" = "" ]]; then + help ffmpeg_mux_cover + return 2 + fi + + local format="''${1}" + local cover="''${2}" + + mkdir out + + case "''${format}" in + # "mka"|"mkv") + # for file in *.''${format}; do + # ffmpeg -i "''${file}" -attach "''${cover}" -map 0 -c copy -metadata:s:t mimetype="image/''${cover##*.}" -metadata:s:t:0 filename="cover.''${cover##*.}" "./out/''${file}" || return 1 + # done + # ;; + *) + for file in *.''${format}; do + # ffmpeg -i "''${file}" -i "''${cover}" -map 0 -map 0:-v? -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"''${file}" || return 1 + ffmpeg -i "''${file}" -i "''${cover}" -map 0 -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"''${file}" || return 1 + done + ;; + esac + + mv out/* . + rm -d out/ && rm "''${2}" + } + + # Generate music metadata from directory structure. + # Top dir is the Artist name like this: `The_Beatles`. + # Next are albums like this: `2010_My_love`. + # Inside are songs like this: `01_sample.flac`. + # Usage: ffmpeg_music_meta + function ffmpeg_music_meta() { + if [[ "''${1}" = "" ]]; then + help ffmpeg_music_meta + return 2 + fi + + local format="''${1}" + + ls *.''${format} &> /dev/null || return 1 + + local artist="''${PWD%/*}"; artist="''${artist##*/}"; artist="''${artist//_/ }" + local album="''${PWD##*/}"; album="''${album#*_}"; album="''${album//_/ }" + local year="''${PWD##*/}"; year="''${year%%_*}" + # local total=$(ls *.''${format} | wc -l) + + mkdir out + + for file in *.''${format}; do + local track="''${file%%_*}"; track=$((10#''${track})); [[ "''${track}" = "" ]] && track=0 + local title="''${file#*_}"; title="''${title%.*}"; title="''${title//_/ }" + + # echo "''${artist}; ''${album}; ''${year}; ''${track}; ''${title}" + # TODO: make it format-specific. + ffmpeg -i "''${file}" -map 0 -c copy -metadata "artist=''${artist}" -metadata "album_artist=''${artist}" -metadata "album=''${album}" -metadata "date=''${year}" -metadata "year=''${year}" -metadata "date_released=''${year}" -metadata "track=''${track}" -metadata "part_number=''${track}" -metadata "title=''${title}" ./out/"''${file}" || return 1 + done + + mv out/* . + rm -d out/ + } + + # Get video FPS. + function _ffprobe_fps() { + local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "''${1}") + [[ "''${fps}" = "" ]] && fps=30 || fps=$((fps)) + echo "''${fps}" + } + + # Get recommended keyframe interval for a file. + _ffprobe_keyint() { + local fps=$(_ffprobe_fps "''${1}") + echo $((fps*5)) + } + + # Get audio bitrage. 128 by default. + function _ffprobe_ba() { + local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "''${1}") + [[ "''${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128 + } + ''; +} diff --git a/module/common/bash/module/Ffmpeg.sh b/module/common/bash/module/Ffmpeg.sh deleted file mode 100644 index d70d58e..0000000 --- a/module/common/bash/module/Ffmpeg.sh +++ /dev/null @@ -1,95 +0,0 @@ -# Mux audio into containers. File names in sound and current dirrectories must match. -# Usage: ffmpeg_mux_audio -function ffmpeg_mux_audio() { - if [[ "${1}" = "" ]]; then - help ffmpeg_mux_audio - return 2 - fi - - for file in *; do ffmpeg -i "$file" -i "$1"/"$file" -c copy -map 0:v:0 -map 1:a:0 -shortest "$2"/"$file"; done -} - -# Mux cover into music file. -# Usage: ffmpeg_mux_cover -function ffmpeg_mux_cover() { - if [[ "${1}" = "" ]]; then - help ffmpeg_mux_cover - return 2 - fi - - local format="${1}" - local cover="${2}" - - mkdir out - - case "${format}" in - # "mka"|"mkv") - # for file in *.${format}; do - # ffmpeg -i "${file}" -attach "${cover}" -map 0 -c copy -metadata:s:t mimetype="image/${cover##*.}" -metadata:s:t:0 filename="cover.${cover##*.}" "./out/${file}" || return 1 - # done - # ;; - *) - for file in *.${format}; do - # ffmpeg -i "${file}" -i "${cover}" -map 0 -map 0:-v? -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"${file}" || return 1 - ffmpeg -i "${file}" -i "${cover}" -map 0 -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"${file}" || return 1 - done - ;; - esac - - mv out/* . - rm -d out/ && rm "${2}" -} - -# Generate music metadata from directory structure. -# Top dir is the Artist name like this: `The_Beatles`. -# Next are albums like this: `2010_My_love`. -# Inside are songs like this: `01_sample.flac`. -# Usage: ffmpeg_music_meta -function ffmpeg_music_meta() { - if [[ "${1}" = "" ]]; then - help ffmpeg_music_meta - return 2 - fi - - local format="${1}" - - ls *.${format} &> /dev/null || return 1 - - local artist="${PWD%/*}"; artist="${artist##*/}"; artist="${artist//_/ }" - local album="${PWD##*/}"; album="${album#*_}"; album="${album//_/ }" - local year="${PWD##*/}"; year="${year%%_*}" - # local total=$(ls *.${format} | wc -l) - - mkdir out - - for file in *.${format}; do - local track="${file%%_*}"; track=$((10#${track})); [[ "${track}" = "" ]] && track=0 - local title="${file#*_}"; title="${title%.*}"; title="${title//_/ }" - - # echo "${artist}; ${album}; ${year}; ${track}; ${title}" - # TODO: make it format-specific. - ffmpeg -i "${file}" -map 0 -c copy -metadata "artist=${artist}" -metadata "album_artist=${artist}" -metadata "album=${album}" -metadata "date=${year}" -metadata "year=${year}" -metadata "date_released=${year}" -metadata "track=${track}" -metadata "part_number=${track}" -metadata "title=${title}" ./out/"${file}" || return 1 - done - - mv out/* . - rm -d out/ -} - -# Get video FPS. -function _ffprobe_fps() { - local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "${1}") - [[ "${fps}" = "" ]] && fps=30 || fps=$((fps)) - echo "${fps}" -} - -# Get recommended keyframe interval for a file. -_ffprobe_keyint() { - local fps=$(_ffprobe_fps "${1}") - echo $((fps*5)) -} - -# Get audio bitrage. 128 by default. -function _ffprobe_ba() { - local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "${1}") - [[ "${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128 -} diff --git a/module/common/bash/module/File.nix b/module/common/bash/module/File.nix new file mode 100644 index 0000000..79f4de2 --- /dev/null +++ b/module/common/bash/module/File.nix @@ -0,0 +1,28 @@ +{ ... }: { + text = '' + # Open file/dir in GUI. + # Usage: open + function open() { + xdg-open "''${@}" + } + alias o="open" + + # Play media file from CLI. All files by default. + # Usage: play [FILE] + function play() { + local targets=''${*} + [[ "''${targets}" = "" ]] && targets=$(_ls_file) + + mpv --no-video ''${targets} + } + + # Play media files shuffled from CLI. All files by default. + # Usage: play_shuffle [FILE] + function play_shuffle() { + local targets=''${*} + [[ "''${targets}" = "" ]] && targets=$(_ls_file) + + mpv --no-video --shuffle ''${targets} + } + ''; +} diff --git a/module/common/bash/module/File.sh b/module/common/bash/module/File.sh deleted file mode 100644 index acbe0e9..0000000 --- a/module/common/bash/module/File.sh +++ /dev/null @@ -1,24 +0,0 @@ -# Open file/dir in GUI. -# Usage: open -function open() { - xdg-open "${@}" -} -alias o="open" - -# Play media file from CLI. All files by default. -# Usage: play [FILE] -function play() { - local targets=${*} - [[ "${targets}" = "" ]] && targets=$(_ls_file) - - mpv --no-video ${targets} -} - -# Play media files shuffled from CLI. All files by default. -# Usage: play_shuffle [FILE] -function play_shuffle() { - local targets=${*} - [[ "${targets}" = "" ]] && targets=$(_ls_file) - - mpv --no-video --shuffle ${targets} -} diff --git a/module/common/bash/module/Find.nix b/module/common/bash/module/Find.nix new file mode 100644 index 0000000..ef94b59 --- /dev/null +++ b/module/common/bash/module/Find.nix @@ -0,0 +1,9 @@ +{ ... }: { + text = '' + # Find all file extensions. + function find_ext() { + local types=($(find -type f | sed -e "s/.*\///" -e "s/^\.//" -e "/\./!d" -e "s/.*\.//")) + echo "''${types[@]}" | tr ' ' '\n' | sort -u + } + ''; +} diff --git a/module/common/bash/module/Find.sh b/module/common/bash/module/Find.sh deleted file mode 100644 index b13c385..0000000 --- a/module/common/bash/module/Find.sh +++ /dev/null @@ -1,26 +0,0 @@ -# Find all file extensions. -function find_ext() { - local types=($(find -type f | sed -e "s/.*\///" -e "s/^\.//" -e "/\./!d" -e "s/.*\.//")) - echo "${types[@]}" | tr ' ' '\n' | sort -u -} - -# Find all modules. -function find_module() { - /usr/bin/env ls "${BASH_PATH}/module" | /usr/bin/env sed -e "s/.sh$//" -} - -# Find all module functions. -# Functions from all modules by default. -# Usage: find_function [MODULE] -function find_function() { - local module="${1}" - [[ "${module}" = "" ]] && module="*" - /usr/bin/env cat "${BASH_PATH}/module"/${module}.sh | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//" -} - -# Autocomplete with module. -_find_module() { - _autocomplete_first $(find_module) -} - -complete -F _find_module find_function diff --git a/module/common/bash/module/Fix.nix b/module/common/bash/module/Fix.nix new file mode 100644 index 0000000..5947edb --- /dev/null +++ b/module/common/bash/module/Fix.nix @@ -0,0 +1,70 @@ +{ ... }: { + text = '' + # Fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb. + # SPEED is one of 10/100/1000 etc. + # Usage: fix_ethernet_speed + function fix_ethernet_speed() { + local device="''${1}" + local speed="''${2}" + + if [[ "''${device}" = "" || "''${speed}" = "" ]]; then + help fix_ethernet_speed + return 2 + fi + + ethtool -s "''${device}" speed "''${speed}" + } + + # Fix nautilus after typing wrong sftp password. + function fix_files_sftp() { + secret-tool clear protocol sftp + } + + # Delete lost Gradle lock files. + function fix_gradle_lock() { + cd "''${HOME}/.gradle" && find -type f | grep \\.lock$ | xargs -- rm + cd - + } + + # Fix Gnome's broken RDP ffs. + # Usage: fix_gnome_rdp + function fix_gnome_rdp() { + local user="''${USERNAME}" + local password="''${1}" + + # Check params. + if [[ "''${password}" = "" ]]; then + help fix_gnome_rdp + return 2 + fi + + # Unlock keyring. PROTIP: Disable password for it in password manager. + pkill -9 -f gnome-keyring-daemon + echo -n "''${user}" | gnome-keyring-daemon --unlock + + # Generate keys. + cd /tmp + openssl genrsa -out rdp-tls.key 4096 + openssl req -new -key rdp-tls.key -subj "/C=US" | openssl x509 -req -days 730 -signkey rdp-tls.key -out rdp-tls.crt + mkdir -p "''${HOME}/.local/share/gnome-remote-desktop/" + mv rdp-tls.key rdp-tls.crt "''${HOME}/.local/share/gnome-remote-desktop/" + + # Configure RDP. + grdctl rdp set-tls-cert "''${HOME}/.local/share/gnome-remote-desktop/rdp-tls.crt" + grdctl rdp set-tls-key "''${HOME}/.local/share/gnome-remote-desktop/rdp-tls.key" + grdctl rdp set-credentials "''${user}" "''${password}" + grdctl rdp disable-view-only + + # Start service. + grdctl rdp enable + systemctl --user start gnome-remote-desktop.service + + # Show status. + grdctl status --show-credentials + systemctl --user status gnome-remote-desktop.service + + # Show extra info. + _warn "You may need to manually restart Desktop sharing via Gnome Settings." + } + ''; +} diff --git a/module/common/bash/module/Fix.sh b/module/common/bash/module/Fix.sh deleted file mode 100644 index 1d9e442..0000000 --- a/module/common/bash/module/Fix.sh +++ /dev/null @@ -1,66 +0,0 @@ -# Fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb. -# SPEED is one of 10/100/1000 etc. -# Usage: fix_ethernet_speed -function fix_ethernet_speed() { - local device="${1}" - local speed="${2}" - - if [[ "${device}" = "" || "${speed}" = "" ]]; then - help fix_ethernet_speed - return 2 - fi - - ethtool -s "${device}" speed "${speed}" -} - -# Fix nautilus after typing wrong sftp password. -function fix_files_sftp() { - secret-tool clear protocol sftp -} - -# Delete lost Gradle lock files. -function fix_gradle_lock() { - cd "${HOME}/.gradle" && find -type f | grep \\.lock$ | xargs -- rm - cd - -} - -# Fix Gnome's broken RDP ffs. -# Usage: fix_gnome_rdp -function fix_gnome_rdp() { - local user="${USERNAME}" - local password="${1}" - - # Check params. - if [[ "${password}" = "" ]]; then - help fix_gnome_rdp - return 2 - fi - - # Unlock keyring. PROTIP: Disable password for it in password manager. - pkill -9 -f gnome-keyring-daemon - echo -n "${user}" | gnome-keyring-daemon --unlock - - # Generate keys. - cd /tmp - openssl genrsa -out rdp-tls.key 4096 - openssl req -new -key rdp-tls.key -subj "/C=US" | openssl x509 -req -days 730 -signkey rdp-tls.key -out rdp-tls.crt - mkdir -p "${HOME}/.local/share/gnome-remote-desktop/" - mv rdp-tls.key rdp-tls.crt "${HOME}/.local/share/gnome-remote-desktop/" - - # Configure RDP. - grdctl rdp set-tls-cert "${HOME}/.local/share/gnome-remote-desktop/rdp-tls.crt" - grdctl rdp set-tls-key "${HOME}/.local/share/gnome-remote-desktop/rdp-tls.key" - grdctl rdp set-credentials "${user}" "${password}" - grdctl rdp disable-view-only - - # Start service. - grdctl rdp enable - systemctl --user start gnome-remote-desktop.service - - # Show status. - grdctl status --show-credentials - systemctl --user status gnome-remote-desktop.service - - # Show extra info. - _warn "You may need to manually restart Desktop sharing via Gnome Settings." -} diff --git a/module/common/bash/module/Git.nix b/module/common/bash/module/Git.nix new file mode 100644 index 0000000..3d0b531 --- /dev/null +++ b/module/common/bash/module/Git.nix @@ -0,0 +1,254 @@ +{ ... }: { + text = '' + # Git push. + function gps() { + git push "''${@}" + } + + # Git push all (branches). Useful for pushing all stuff to a new remote. + function gpsa() { + local remotes=($(git remote)) + for remote in ''${remotes[@]}; do + echo -n "''${remote}: " + git push "''${remote}" --tags "refs/remotes/origin/*:refs/heads/*" + done + } + + # Git force push. + function gpsf() { + git push --force "''${@}" + } + + # Git pull. + function gpl() { + git pull "''${@}" + } + + # Git log. + function gl() { + git log "''${@}" + } + + # Git status. + function gs() { + git status "''${@}" + } + + # Git stash. + function gst() { + git stash "''${@}" + } + + # Git diff. + function gd() { + git diff "''${@}" + } + + # Git commit. + function gc() { + git commit -m "''${@}" + } + + # Git checkout. + function gch() { + git checkout "''${@}" + } + + # Git checkout branch. + # Usage: gchb + function gchb() { + git checkout -b "''${@}" + } + + # Git branch. + function gb() { + git branch --all "''${@}" + } + + # Git branch delete. + # Usage: gbd + function gbd() { + git branch -D "''${@}" + } + + # Git branch delete all except current. + function gbda() { + git branch | grep -v ^* | xargs git branch -D + } + + # Git fetch all. + function gf() { + git fetch --all -v -p + } + + # Git tag. + function gt() { + git tag "''${@}" + } + + # Git ignore files. + function gi() { + git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached + } + + # Git patch create. + # Usage: gpc + function gpc() { + git diff > "''${@}" + } + + # Git patch (apply). + # Usage: gp + function gp() { + git apply "''${@}" + } + + # Run git garbage collection. + function ggc() { + git gc --aggressive --no-cruft --prune=now + } + + # Preview diff while adding. Adds current dir by default. + # Usage: ga [FILES] + function ga() { + local target=''${@} + + if [[ "''${target}" = "" ]]; then + target="." + fi + + git diff ''${target} + git add ''${target} + } + + # Rebase by X commits or from root. When COUNT is 0 - rebase from root. Default is 2. + # Usage: gr [COMMIT COUNT] + function gr() { + local base="''${1}" + + # rebase last 2 commits by default. + if [[ "''${base}" = "" ]]; then + base="2" + fi + + # if 0, rebase from root. else from specified base. + if [[ "''${base}" = "0" ]]; then + git rebase -i --root + else + git rebase -i HEAD~''${base} + fi + } + + # Specify git user as Dmitry Voronin with provided email. + # Usage: gu [EMAIL] + function gu() { + local name="Dmitry Voronin" + local email="''${1}" + + if [[ "''${name}" = "" || "''${email}" = "" ]]; then + echo "usage: gu [EMAIL]" + return 2 + fi + + git config user.name "''${name}" + git config user.email "''${email}" + } + + # Get my git repo. + # Usage: gg + function gg() { + local repo="''${1}" + + if [[ "''${repo}" = "" ]]; then + help gg + return 2 + fi + + git clone https://git.voronind.com/voronind/"''${repo}" + } + + # See diff for a specific commit. Last commit by default. + # Usage: gdc [COMMITHASH] + function gdc() { + local hash="''${1}" + [[ "''${hash}" = "" ]] && hash="HEAD" + git diff "''${hash}^!" + } + + # Get version number based on commit count. + function gv() { + git rev-list HEAD --count + } + + # Open the remote web url in default browser. + # Usage: gw [REMOTE] + function gw() { + local remote="''${1}" + [[ "''${remote}" = "" ]] && remote="$(git remote | head -n1)" + + local url="$(git remote get-url ''${remote})" + open "''${url}" + } + + # Show current branch. + function _git_current_branch() { + git branch --show-current 2> /dev/null + } + + # Show origin's url. + function _git_origin_url() { + git remote get-url origin + } + + # Get this dotfiles url. + function _git_dotfiles_url() { + echo 'https://git.voronind.com/voronind/linux.git' + } + + # Check if current git repo is this dotfiles. + function _git_is_dotfiles() { + # [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]] + local dir="''${PWD}" + + while [[ "''${dir}" != "" ]]; do + if [[ -d "''${dir}/.git" ]]; then + if [[ "''${dir}" = "''${HOME}" ]] || [[ "''${dir}" = "$(realpath ''${HOME})" ]]; then + return 0 + else + return 1 + fi + fi + + dir="''${dir%/*}" + done + } + + # Autocomplete. + _completion_loader git &> /dev/null + __git_complete gps _git_push &> /dev/null + __git_complete gpsf _git_push &> /dev/null + __git_complete gpl _git_pull &> /dev/null + __git_complete gl _git_log &> /dev/null + __git_complete gs _git_status &> /dev/null + __git_complete gst _git_stash &> /dev/null + __git_complete gd _git_diff &> /dev/null + __git_complete gdc _git_diff &> /dev/null + __git_complete gc _git_commit &> /dev/null + __git_complete gch _git_checkout &> /dev/null + __git_complete gchb _git_checkout &> /dev/null + __git_complete gb _git_branch &> /dev/null + __git_complete gbd _git_branch &> /dev/null + __git_complete gf _git_fetch &> /dev/null + __git_complete gt _git_tag &> /dev/null + __git_complete gp _git_apply &> /dev/null + __git_complete ga _git_add &> /dev/null + __git_complete gw _git_pull &> /dev/null + + # Autocomplete with my git emails. + function _gu() { + _autocomplete_first account@voronind.com dd.voronin@fsight.ru + } + + complete -F _gu gu + ''; +} diff --git a/module/common/bash/module/Git.sh b/module/common/bash/module/Git.sh deleted file mode 100644 index cb07f71..0000000 --- a/module/common/bash/module/Git.sh +++ /dev/null @@ -1,250 +0,0 @@ -# Git push. -function gps() { - git push "${@}" -} - -# Git push all (branches). Useful for pushing all stuff to a new remote. -function gpsa() { - local remotes=($(git remote)) - for remote in ${remotes[@]}; do - echo -n "${remote}: " - git push "${remote}" --tags "refs/remotes/origin/*:refs/heads/*" - done -} - -# Git force push. -function gpsf() { - git push --force "${@}" -} - -# Git pull. -function gpl() { - git pull "${@}" -} - -# Git log. -function gl() { - git log "${@}" -} - -# Git status. -function gs() { - git status "${@}" -} - -# Git stash. -function gst() { - git stash "${@}" -} - -# Git diff. -function gd() { - git diff "${@}" -} - -# Git commit. -function gc() { - git commit -m "${@}" -} - -# Git checkout. -function gch() { - git checkout "${@}" -} - -# Git checkout branch. -# Usage: gchb -function gchb() { - git checkout -b "${@}" -} - -# Git branch. -function gb() { - git branch --all "${@}" -} - -# Git branch delete. -# Usage: gbd -function gbd() { - git branch -D "${@}" -} - -# Git branch delete all except current. -function gbda() { - git branch | grep -v ^* | xargs git branch -D -} - -# Git fetch all. -function gf() { - git fetch --all -v -p -} - -# Git tag. -function gt() { - git tag "${@}" -} - -# Git ignore files. -function gi() { - git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached -} - -# Git patch create. -# Usage: gpc -function gpc() { - git diff > "${@}" -} - -# Git patch (apply). -# Usage: gp -function gp() { - git apply "${@}" -} - -# Run git garbage collection. -function ggc() { - git gc --aggressive --no-cruft --prune=now -} - -# Preview diff while adding. Adds current dir by default. -# Usage: ga [FILES] -function ga() { - local target=${@} - - if [[ "${target}" = "" ]]; then - target="." - fi - - git diff ${target} - git add ${target} -} - -# Rebase by X commits or from root. When COUNT is 0 - rebase from root. Default is 2. -# Usage: gr [COMMIT COUNT] -function gr() { - local base="${1}" - - # rebase last 2 commits by default. - if [[ "${base}" = "" ]]; then - base="2" - fi - - # if 0, rebase from root. else from specified base. - if [[ "${base}" = "0" ]]; then - git rebase -i --root - else - git rebase -i HEAD~${base} - fi -} - -# Specify git user as Dmitry Voronin with provided email. -# Usage: gu [EMAIL] -function gu() { - local name="Dmitry Voronin" - local email="${1}" - - if [[ "${name}" = "" || "${email}" = "" ]]; then - echo "usage: gu [EMAIL]" - return 2 - fi - - git config user.name "${name}" - git config user.email "${email}" -} - -# Get my git repo. -# Usage: gg -function gg() { - local repo="${1}" - - if [[ "${repo}" = "" ]]; then - help gg - return 2 - fi - - git clone https://git.voronind.com/voronind/"${repo}" -} - -# See diff for a specific commit. Last commit by default. -# Usage: gdc [COMMITHASH] -function gdc() { - local hash="${1}" - [[ "${hash}" = "" ]] && hash="HEAD" - git diff "${hash}^!" -} - -# Get version number based on commit count. -function gv() { - git rev-list HEAD --count -} - -# Open the remote web url in default browser. -# Usage: gw [REMOTE] -function gw() { - local remote="${1}" - [[ "${remote}" = "" ]] && remote="$(git remote | head -n1)" - - local url="$(git remote get-url ${remote})" - open "${url}" -} - -# Show current branch. -function _git_current_branch() { - git branch --show-current 2> /dev/null -} - -# Show origin's url. -function _git_origin_url() { - git remote get-url origin -} - -# Get this dotfiles url. -function _git_dotfiles_url() { - echo 'https://git.voronind.com/voronind/linux.git' -} - -# Check if current git repo is this dotfiles. -function _git_is_dotfiles() { - # [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]] - local dir="${PWD}" - - while [[ "${dir}" != "" ]]; do - if [[ -d "${dir}/.git" ]]; then - if [[ "${dir}" = "${HOME}" ]] || [[ "${dir}" = "$(realpath ${HOME})" ]]; then - return 0 - else - return 1 - fi - fi - - dir="${dir%/*}" - done -} - -# Autocomplete. -_completion_loader git &> /dev/null -__git_complete gps _git_push &> /dev/null -__git_complete gpsf _git_push &> /dev/null -__git_complete gpl _git_pull &> /dev/null -__git_complete gl _git_log &> /dev/null -__git_complete gs _git_status &> /dev/null -__git_complete gst _git_stash &> /dev/null -__git_complete gd _git_diff &> /dev/null -__git_complete gdc _git_diff &> /dev/null -__git_complete gc _git_commit &> /dev/null -__git_complete gch _git_checkout &> /dev/null -__git_complete gchb _git_checkout &> /dev/null -__git_complete gb _git_branch &> /dev/null -__git_complete gbd _git_branch &> /dev/null -__git_complete gf _git_fetch &> /dev/null -__git_complete gt _git_tag &> /dev/null -__git_complete gp _git_apply &> /dev/null -__git_complete ga _git_add &> /dev/null -__git_complete gw _git_pull &> /dev/null - -# Autocomplete with my git emails. -function _gu() { - _autocomplete_first account@voronind.com dd.voronin@fsight.ru -} - -complete -F _gu gu diff --git a/module/common/bash/module/Group.nix b/module/common/bash/module/Group.nix new file mode 100644 index 0000000..a6f85bd --- /dev/null +++ b/module/common/bash/module/Group.nix @@ -0,0 +1,73 @@ +{ ... }: { + text = '' + # Group files by extension. + # Usage: group_ext [FILES] + function group_ext() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + process() { + local ext=''${target##*.} + [[ -d "''${target}" ]] && { _iterate_skip "Is a directory."; return 0; } + [[ "''${ext}" = "''${target}" ]] && { _iterate_skip "No extension."; return 0; } + + mkdir ''${ext} 2> /dev/null + + mv -- ''${target} ./''${ext}/''${target} + } + + _iterate_targets process ''${targets[@]} + } + + # Group files and dirs by year. + # Usage: group_year [FILES] + function group_year() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls)) + + process() { + local year=$(stat --format=%y ''${target}) + year=''${year%%-*} + + mkdir ''${year} 2> /dev/null + + mv -- ''${target} ./''${year}/''${target} + } + + _iterate_targets process ''${targets[@]} + } + + # Copy files from current year to the named dir. + # Usage: group_year_copy [FILES] + function group_year_copy() { + local IFS=$'\n' + local selected_year="''${1}" + local targets=(''${@:2}) + + if [[ "''${selected_year}" = "" ]]; then + help group_year_copy + return 2 + fi + + # All files by default. + [[ "''${targets}" = "" ]] && targets=($(ls)) + + mkdir ''${selected_year} 2> /dev/null + + process() { + local year=$(stat --format=%y ''${target}) + year=''${year%%-*} + + if [[ "''${year}" = "''${selected_year}" ]]; then + rcp -- ''${target} ./''${selected_year}/ + else + _iterate_skip + fi + } + + _iterate_targets process ''${targets[@]} + } + ''; +} diff --git a/module/common/bash/module/Group.sh b/module/common/bash/module/Group.sh deleted file mode 100644 index 15e4b7b..0000000 --- a/module/common/bash/module/Group.sh +++ /dev/null @@ -1,69 +0,0 @@ -# Group files by extension. -# Usage: group_ext [FILES] -function group_ext() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - process() { - local ext=${target##*.} - [[ -d "${target}" ]] && { _iterate_skip "Is a directory."; return 0; } - [[ "${ext}" = "${target}" ]] && { _iterate_skip "No extension."; return 0; } - - mkdir ${ext} 2> /dev/null - - mv -- ${target} ./${ext}/${target} - } - - _iterate_targets process ${targets[@]} -} - -# Group files and dirs by year. -# Usage: group_year [FILES] -function group_year() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(ls)) - - process() { - local year=$(stat --format=%y ${target}) - year=${year%%-*} - - mkdir ${year} 2> /dev/null - - mv -- ${target} ./${year}/${target} - } - - _iterate_targets process ${targets[@]} -} - -# Copy files from current year to the named dir. -# Usage: group_year_copy [FILES] -function group_year_copy() { - local IFS=$'\n' - local selected_year="${1}" - local targets=(${@:2}) - - if [[ "${selected_year}" = "" ]]; then - help group_year_copy - return 2 - fi - - # All files by default. - [[ "${targets}" = "" ]] && targets=($(ls)) - - mkdir ${selected_year} 2> /dev/null - - process() { - local year=$(stat --format=%y ${target}) - year=${year%%-*} - - if [[ "${year}" = "${selected_year}" ]]; then - rcp -- ${target} ./${selected_year}/ - else - _iterate_skip - fi - } - - _iterate_targets process ${targets[@]} -} diff --git a/module/common/bash/module/Help.nix b/module/common/bash/module/Help.nix new file mode 100644 index 0000000..f75f6e8 --- /dev/null +++ b/module/common/bash/module/Help.nix @@ -0,0 +1,29 @@ +{ ... }: { + text = '' + # Get help about dotfiles bash function. + # Usage: help + function help() { + local fun="''${1}" + + if [[ "''${fun}" = "" ]] || [[ "$(find_function | /usr/bin/env grep ''${fun})" = "" ]]; then + help help + return 2 + fi + + /usr/bin/env sed -e '$s/$/\n/' -s "''${BASH_PATH}/module"/* | /usr/bin/env sed -n -e "/function ''${fun}()/q;p" | /usr/bin/env tac | /usr/bin/env sed -n -e "/^$/q;p" | /usr/bin/env tac | /usr/bin/env sed -e "s/^# \+//" -e "\$i \ " + } + + # Short for help. + # Usage: h + function h() { + help "''${@}" + } + + # Autocomplete with available functions. + function _help_functions() { + _autocomplete_first $(find_function) + } + + complete -F _help_functions help h + ''; +} diff --git a/module/common/bash/module/Help.sh b/module/common/bash/module/Help.sh deleted file mode 100644 index 37354c4..0000000 --- a/module/common/bash/module/Help.sh +++ /dev/null @@ -1,25 +0,0 @@ -# Get help about dotfiles bash function. -# Usage: help -function help() { - local fun="${1}" - - if [[ "${fun}" = "" ]] || [[ "$(find_function | /usr/bin/env grep ${fun})" = "" ]]; then - help help - return 2 - fi - - /usr/bin/env sed -e '$s/$/\n/' -s "${BASH_PATH}/module"/* | /usr/bin/env sed -n -e "/function ${fun}()/q;p" | /usr/bin/env tac | /usr/bin/env sed -n -e "/^$/q;p" | /usr/bin/env tac | /usr/bin/env sed -e "s/^# \+//" -e "\$i \ " -} - -# Short for help. -# Usage: h -function h() { - help "${@}" -} - -# Autocomplete with available functions. -function _help_functions() { - _autocomplete_first $(find_function) -} - -complete -F _help_functions help h diff --git a/module/common/bash/module/Ls.nix b/module/common/bash/module/Ls.nix new file mode 100644 index 0000000..223d715 --- /dev/null +++ b/module/common/bash/module/Ls.nix @@ -0,0 +1,68 @@ +{ ... }: { + text = '' + # Unset possible system-defined aliases. + unalias l ll lll llll la lla &> /dev/null + unset l ll lll llll la lla &> /dev/null + + # List files in dirs. + # Current dir by default. + # Usage: l [DIRS] + function l() { + ls -lhv --si --group-directories-first --color=auto -- "$@" + } + + # List last modified files first. + # Current dir by default. + # Usage: ll [DIRS] + function ll() { + ls -lhvtr --si --color=auto -- "$@" + } + + # List files in tree structure. + # Current dir by default. + # Depth can be omitted by passing `-` (dash). + # Usage: lll [DEPTH] [DIRS] + function lll() { + local IFS=$'\n' + local depth="''${1}" + local target=("''${@:2}") + + [[ "''${target}" = "" ]] && target="." + [[ "''${depth}" = "" ]] && depth=666 + [[ "''${depth}" = "-" ]] && depth=666 + + tree -a -L "''${depth}" -- "''${target[@]}" + } + + # List files recursively. + # Current dir by default. + # Usage: llll [DIRS] + function llll() { + ls -RlAhv --si --group-directories-first --color=auto -- "$@" + } + + # List all files in dirs, incl. hidden files. + # Current dir by default. + # Usage: la [DIRS] + function la() { + ls -lAh --si --group-directories-first --color=auto -- "$@" + } + + # List all files in dirs, incl. hidden files, sorted by mtime. + # Current dir by default. + # Usage: lla [DIRS] + function lla() { + ls -lAhtr --si --color=auto -- "$@" + } + + # List only files. + function _ls_file() { + ls --classify | grep -v \/$ + } + + # List only dirs. + function _ls_dir() { + ls --classify | grep \/$ | sed -e "s/\/$//" + } + ''; +} diff --git a/module/common/bash/module/Ls.sh b/module/common/bash/module/Ls.sh deleted file mode 100644 index 12fe16e..0000000 --- a/module/common/bash/module/Ls.sh +++ /dev/null @@ -1,64 +0,0 @@ -# Unset possible system-defined aliases. -unalias l ll lll llll la lla &> /dev/null -unset l ll lll llll la lla &> /dev/null - -# List files in dirs. -# Current dir by default. -# Usage: l [DIRS] -function l() { - ls -lhv --si --group-directories-first --color=auto -- "$@" -} - -# List last modified files first. -# Current dir by default. -# Usage: ll [DIRS] -function ll() { - ls -lhvtr --si --color=auto -- "$@" -} - -# List files in tree structure. -# Current dir by default. -# Depth can be omitted by passing `-` (dash). -# Usage: lll [DEPTH] [DIRS] -function lll() { - local IFS=$'\n' - local depth="${1}" - local target=("${@:2}") - - [[ "${target}" = "" ]] && target="." - [[ "${depth}" = "" ]] && depth=666 - [[ "${depth}" = "-" ]] && depth=666 - - tree -a -L "${depth}" -- "${target[@]}" -} - -# List files recursively. -# Current dir by default. -# Usage: llll [DIRS] -function llll() { - ls -RlAhv --si --group-directories-first --color=auto -- "$@" -} - -# List all files in dirs, incl. hidden files. -# Current dir by default. -# Usage: la [DIRS] -function la() { - ls -lAh --si --group-directories-first --color=auto -- "$@" -} - -# List all files in dirs, incl. hidden files, sorted by mtime. -# Current dir by default. -# Usage: lla [DIRS] -function lla() { - ls -lAhtr --si --color=auto -- "$@" -} - -# List only files. -function _ls_file() { - ls --classify | grep -v \/$ -} - -# List only dirs. -function _ls_dir() { - ls --classify | grep \/$ | sed -e "s/\/$//" -} diff --git a/module/common/bash/module/Markdown.nix b/module/common/bash/module/Markdown.nix new file mode 100644 index 0000000..b8cf8da --- /dev/null +++ b/module/common/bash/module/Markdown.nix @@ -0,0 +1,19 @@ +{ ... }: { + text = '' + # Render markdown in browser using Gitea API. Because I want consistency with Gitea web render. + # Works only inside LAN. + # Usage: markdown_render + function markdown_render() { + local IFS=$'\n' + local file="''${1}" + local render="markdown_render.html" + + if [[ "''${file}" = "" ]]; then + help markdown_render + return 2 + fi + + curl -X POST https://git.voronind.com/markdown -d "$(cat ''${file})" > "''${render}" && o "''${render}" && sleep 2 && rm "''${render}" + } + ''; +} diff --git a/module/common/bash/module/Markdown.sh b/module/common/bash/module/Markdown.sh deleted file mode 100644 index 7b9c120..0000000 --- a/module/common/bash/module/Markdown.sh +++ /dev/null @@ -1,15 +0,0 @@ -# Render markdown in browser using Gitea API. Because I want consistency with Gitea web render. -# Works only inside LAN. -# Usage: markdown_render -function markdown_render() { - local IFS=$'\n' - local file="${1}" - local render="markdown_render.html" - - if [[ "${file}" = "" ]]; then - help markdown_render - return 2 - fi - - curl -X POST https://git.voronind.com/markdown -d "$(cat ${file})" > "${render}" && o "${render}" && sleep 2 && rm "${render}" -} diff --git a/module/common/bash/module/Monitor.nix b/module/common/bash/module/Monitor.nix new file mode 100644 index 0000000..4f5beee --- /dev/null +++ b/module/common/bash/module/Monitor.nix @@ -0,0 +1,13 @@ +{ ... }: { + text = '' + # Enable monitors. + function monon() { + swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power on' + } + + # Disable monitors. + function monoff() { + swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power off' + } + ''; +} diff --git a/module/common/bash/module/Monitor.sh b/module/common/bash/module/Monitor.sh deleted file mode 100644 index 961329e..0000000 --- a/module/common/bash/module/Monitor.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Enable monitors. -function monon() { - swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power on' -} - -# Disable monitors. -function monoff() { - swaymsg 'output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" power off' -} diff --git a/module/common/bash/module/Name.nix b/module/common/bash/module/Name.nix new file mode 100644 index 0000000..0a2d67c --- /dev/null +++ b/module/common/bash/module/Name.nix @@ -0,0 +1,399 @@ +{ ... }: { + text = '' + # Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives! + # Usage: name [FILES] + function name() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls)) + + process() { + # Skip archive. + if $(_is_archive ''${target}); then + _iterate_skip "File is an archive, skip." + return 0 + fi + + if [[ -d "''${target}" ]]; then + local new_name=$(parse_snake ''${target}) + [[ -e "''${new_name}" ]] && return 0 + + mv -- ''${target} ''${new_name} && echo ''${new_name} + else + local ext=".''${target##*.}" + local name=''${target%.*} + [[ "''${ext}" = ".''${target}" ]] && ext="" + + local new_name="$(parse_pascal ''${name})''${ext}" + [[ -e "''${new_name}" ]] && return 0 + + mv -- ''${target} ''${new_name} && echo ''${new_name} + fi + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files with provided parser, i.e. `parse_simple`. + # All files by default. + # Usage: name_parse [FILES] + function name_parse() { + local IFS=$'\n' + local parser=''${1} + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=([^.]*) + + if [[ "''${parser}" = "" ]]; then + help name_parse + return 2 + fi + + process() { + # Skip archive. + if $(_is_archive ''${target}); then + _iterate_skip "File is an archive, skip." + return 0 + fi + + # parse new name. + local ext="" + local name="''${target}" + + # ext only for files. + if [[ -f "''${target}" ]]; then + ext=".''${target##*.}" + name="''${target%.*}" + fi + + # Files w/o extension support. + [[ "''${ext#.}" = "''${name}" ]] && ext="" + + # Get new name. + local new_name=$(''${parser} "''${name}")''${ext,,} + + # check if same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # check if target name already exists. + if [[ -f "''${new_name}" ]]; then + _error "''${new_name}: Already exists!" + return 1 + fi + + # rename target. + mv -- "''${target}" "''${new_name}" && echo "''${new_name}" + } + + _iterate_targets process ''${targets[@]} + } + + # Rename all files to their hashes while keeping extensions. + # All files by default. + # Usage: name_hash [FILES] + function name_hash() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + process() { + # extract extension. + local extension="''${target##*.}" + if [[ "''${extension}" = "''${target}" ]]; then + extension="" + else + extension=".''${extension}" + fi + + # hash the new name. + local hash=$(pv "''${target}" | sha1sum | cut -d\ -f1) + new_name="''${hash,,}''${extension,,}" + + # check if same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Check hashes for previously renamed files. + # All files by default. + # Usage: name_hash_check [FILES] + function name_hash_check() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=([^.]*) + + process() { + # extract hashes. + local stored="''${target%%.*}" + local actual=$(pv "''${target}" | sha1sum | cut -d\ -f1) + + # compare hashes. + if [[ "''${stored}" != "''${actual}" ]]; then + _error "Failed." + return 1 + fi + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files for Jellyfin shows, i.e. `Episode S01E01.mkv` + # All files by default. + # Usage: name_show [FILES] + function name_show() { + local IFS=$'\n' + local season="$(realpath .)"; season="''${season##*\ }" + local episode=0 + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + # Error when no season number specified. + if [[ "''${season}" = "" ]]; then + _error "Could not determine season number." + return 2 + fi + + process() { + ((episode++)) + + # extract new name. + local new_name="Episode S''${season}E$(printf %02d ''${episode}).''${target##*.}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files for Kavita manga format. + # All files by default. + # Usage: name_manga [FILES] + function name_manga() { + local IFS=$'\n' + local manga=''${PWD##*/} + local season=''${1} + local episode=0 + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + # Error when no season number specified. + if [[ "''${season}" = "" ]]; then + help name_manga + return 2 + fi + + process() { + ((episode++)) + + # Extract new name. + local new_name="''${manga} Vol.''${season} Ch.''${episode}.''${target##*.}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files for ffmpeg_music_meta format. + # All files by default. + # Usage: name_music [FILES] + function name_music() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls)) + + process() { + # Extract new name. + local ext=''${target##*.} + + if [[ -d "''${target}" ]]; then + local new_name="$(parse_titlecase $(parse_simple ''${target%.*}))" + else + local new_name="$(parse_titlecase $(parse_simple ''${target%.*})).''${ext}" + fi + + # Skip on no change. + [[ "''${target%/}" = "''${new_name}" ]] && return 0 + + # Rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files with new extension. + # All files by default. + # Usage: name_ext [FILES] + function name_ext() { + local IFS=$'\n' + local extension=''${1} + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + # Error when no new extension specified. + if [[ "''${extension}" = "" ]]; then + help name_ext + return 2 + fi + + process() { + # Extract new name. + local new_name="''${target%.*}"."''${extension}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Change file name prefix. + # All matching files by default. + # Usage: name_prefix [FILES] + function name_prefix() { + local IFS=$'\n' + local old=''${1} + local new=''${2} + local targets=(''${@:3}) + [[ "''${targets}" = "" ]] && targets=(''${old}*) + + process() { + # Create new name. + local new_name="''${new}''${target#$old}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Change file name postfix. + # All matching files by default. + # Usage: name_postfix [FILES] + function name_postfix() { + local IFS=$'\n' + local old=''${1} + local new=''${2} + local targets=(''${@:3}) + [[ "''${targets}" = "" ]] && targets=(*''${old}) + + process() { + # Create new name. + local new_name="''${target%$old}''${new}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Replace part of the name. + # All matching files by default. + # Usage: name_replace [FILES] + function name_replace() { + local IFS=$'\n' + local old=''${1} + local new=''${2} + local targets=(''${@:3}) + [[ "''${targets}" = "" ]] && targets=(*''${old}*) + + process() { + # Create new name. + local new_name="''${target//$old/$new}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Fix numbering for numbered files. I.e if there are 10 items and some of them start without zero, then append zero to it. 1..10 -> 01..10. + # Usage: name_fix_numbering [FILES] + function name_fix_numbering() { + local IFS=$'\n' + local highest=0 + local power=0 + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls | grep "^[0-9]")) + + # Count leading zeroes. + for target in "''${targets[@]}"; do + # Check that starts with a digit. + [[ "''${target}" =~ ^[0-9] ]] || continue + + local digits=($(parse_ints "''${target}")) + local digit="''${digits[0]}" + digit=$((10#''${digit})) + + [[ "''${digit}" -gt "''${highest}" ]] && highest="''${digit}" + done + + local i=''${highest} + while [[ i -gt 0 ]]; do + ((power++)) + i=$((''${i}/10)) + done + + process() { + # Check that starts with a digit. + if [[ ! "''${target}" =~ ^[0-9] ]]; then + _error "Does not start with a digit!" + return 1 + fi + + # Prepare new name. + local digits=($(parse_ints "''${target}")) + local digit="''${digits[0]}" + digit=$((10#''${digit})) + local new_name=$(printf "%0''${power}d" "''${digit}")"''${target#''${digits[0]}}" + + # Skip if the same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Check that file does not exist. + if [[ -e "''${new_name}" ]]; then + _error "''${new_name}: File exists!" + return 1 + fi + + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + function _comp_name_parse() { + _autocomplete_first_ls $(find_function | grep ^parse) + } + + complete -o filenames -F _comp_name_parse name_parse + ''; +} diff --git a/module/common/bash/module/Name.sh b/module/common/bash/module/Name.sh deleted file mode 100644 index d05943f..0000000 --- a/module/common/bash/module/Name.sh +++ /dev/null @@ -1,395 +0,0 @@ -# Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives! -# Usage: name [FILES] -function name() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(ls)) - - process() { - # Skip archive. - if $(_is_archive ${target}); then - _iterate_skip "File is an archive, skip." - return 0 - fi - - if [[ -d "${target}" ]]; then - local new_name=$(parse_snake ${target}) - [[ -e "${new_name}" ]] && return 0 - - mv -- ${target} ${new_name} && echo ${new_name} - else - local ext=".${target##*.}" - local name=${target%.*} - [[ "${ext}" = ".${target}" ]] && ext="" - - local new_name="$(parse_pascal ${name})${ext}" - [[ -e "${new_name}" ]] && return 0 - - mv -- ${target} ${new_name} && echo ${new_name} - fi - } - - _iterate_targets process ${targets[@]} -} - -# Rename files with provided parser, i.e. `parse_simple`. -# All files by default. -# Usage: name_parse [FILES] -function name_parse() { - local IFS=$'\n' - local parser=${1} - local targets=(${@:2}) - [[ "${targets}" = "" ]] && targets=([^.]*) - - if [[ "${parser}" = "" ]]; then - help name_parse - return 2 - fi - - process() { - # Skip archive. - if $(_is_archive ${target}); then - _iterate_skip "File is an archive, skip." - return 0 - fi - - # parse new name. - local ext="" - local name="${target}" - - # ext only for files. - if [[ -f "${target}" ]]; then - ext=".${target##*.}" - name="${target%.*}" - fi - - # Files w/o extension support. - [[ "${ext#.}" = "${name}" ]] && ext="" - - # Get new name. - local new_name=$(${parser} "${name}")${ext,,} - - # check if same name. - [[ "${target}" = "${new_name}" ]] && return 0 - - # check if target name already exists. - if [[ -f "${new_name}" ]]; then - _error "${new_name}: Already exists!" - return 1 - fi - - # rename target. - mv -- "${target}" "${new_name}" && echo "${new_name}" - } - - _iterate_targets process ${targets[@]} -} - -# Rename all files to their hashes while keeping extensions. -# All files by default. -# Usage: name_hash [FILES] -function name_hash() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - process() { - # extract extension. - local extension="${target##*.}" - if [[ "${extension}" = "${target}" ]]; then - extension="" - else - extension=".${extension}" - fi - - # hash the new name. - local hash=$(pv "${target}" | sha1sum | cut -d\ -f1) - new_name="${hash,,}${extension,,}" - - # check if same name. - [[ "${target}" = "${new_name}" ]] && return 0 - - # rename target. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Check hashes for previously renamed files. -# All files by default. -# Usage: name_hash_check [FILES] -function name_hash_check() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=([^.]*) - - process() { - # extract hashes. - local stored="${target%%.*}" - local actual=$(pv "${target}" | sha1sum | cut -d\ -f1) - - # compare hashes. - if [[ "${stored}" != "${actual}" ]]; then - _error "Failed." - return 1 - fi - } - - _iterate_targets process ${targets[@]} -} - -# Rename files for Jellyfin shows, i.e. `Episode S01E01.mkv` -# All files by default. -# Usage: name_show [FILES] -function name_show() { - local IFS=$'\n' - local season="$(realpath .)"; season="${season##*\ }" - local episode=0 - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - # Error when no season number specified. - if [[ "${season}" = "" ]]; then - _error "Could not determine season number." - return 2 - fi - - process() { - ((episode++)) - - # extract new name. - local new_name="Episode S${season}E$(printf %02d ${episode}).${target##*.}" - - # Skip on no change. - [[ "${target}" = "${new_name}" ]] && return 0 - - # rename target. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Rename files for Kavita manga format. -# All files by default. -# Usage: name_manga [FILES] -function name_manga() { - local IFS=$'\n' - local manga=${PWD##*/} - local season=${1} - local episode=0 - local targets=(${@:2}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - # Error when no season number specified. - if [[ "${season}" = "" ]]; then - help name_manga - return 2 - fi - - process() { - ((episode++)) - - # Extract new name. - local new_name="${manga} Vol.${season} Ch.${episode}.${target##*.}" - - # Skip on no change. - [[ "${target}" = "${new_name}" ]] && return 0 - - # Rename target. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Rename files for ffmpeg_music_meta format. -# All files by default. -# Usage: name_music [FILES] -function name_music() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(ls)) - - process() { - # Extract new name. - local ext=${target##*.} - - if [[ -d "${target}" ]]; then - local new_name="$(parse_titlecase $(parse_simple ${target%.*}))" - else - local new_name="$(parse_titlecase $(parse_simple ${target%.*})).${ext}" - fi - - # Skip on no change. - [[ "${target%/}" = "${new_name}" ]] && return 0 - - # Rename target. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Rename files with new extension. -# All files by default. -# Usage: name_ext [FILES] -function name_ext() { - local IFS=$'\n' - local extension=${1} - local targets=(${@:2}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - # Error when no new extension specified. - if [[ "${extension}" = "" ]]; then - help name_ext - return 2 - fi - - process() { - # Extract new name. - local new_name="${target%.*}"."${extension}" - - # Skip on no change. - [[ "${target}" = "${new_name}" ]] && return 0 - - # Rename target. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Change file name prefix. -# All matching files by default. -# Usage: name_prefix [FILES] -function name_prefix() { - local IFS=$'\n' - local old=${1} - local new=${2} - local targets=(${@:3}) - [[ "${targets}" = "" ]] && targets=(${old}*) - - process() { - # Create new name. - local new_name="${new}${target#$old}" - - # Skip on no change. - [[ "${target}" = "${new_name}" ]] && return 0 - - # Rename. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Change file name postfix. -# All matching files by default. -# Usage: name_postfix [FILES] -function name_postfix() { - local IFS=$'\n' - local old=${1} - local new=${2} - local targets=(${@:3}) - [[ "${targets}" = "" ]] && targets=(*${old}) - - process() { - # Create new name. - local new_name="${target%$old}${new}" - - # Skip on no change. - [[ "${target}" = "${new_name}" ]] && return 0 - - # Rename. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Replace part of the name. -# All matching files by default. -# Usage: name_replace [FILES] -function name_replace() { - local IFS=$'\n' - local old=${1} - local new=${2} - local targets=(${@:3}) - [[ "${targets}" = "" ]] && targets=(*${old}*) - - process() { - # Create new name. - local new_name="${target//$old/$new}" - - # Skip on no change. - [[ "${target}" = "${new_name}" ]] && return 0 - - # Rename. - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -# Fix numbering for numbered files. I.e if there are 10 items and some of them start without zero, then append zero to it. 1..10 -> 01..10. -# Usage: name_fix_numbering [FILES] -function name_fix_numbering() { - local IFS=$'\n' - local highest=0 - local power=0 - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(ls | grep "^[0-9]")) - - # Count leading zeroes. - for target in "${targets[@]}"; do - # Check that starts with a digit. - [[ "${target}" =~ ^[0-9] ]] || continue - - local digits=($(parse_ints "${target}")) - local digit="${digits[0]}" - digit=$((10#${digit})) - - [[ "${digit}" -gt "${highest}" ]] && highest="${digit}" - done - - local i=${highest} - while [[ i -gt 0 ]]; do - ((power++)) - i=$((${i}/10)) - done - - process() { - # Check that starts with a digit. - if [[ ! "${target}" =~ ^[0-9] ]]; then - _error "Does not start with a digit!" - return 1 - fi - - # Prepare new name. - local digits=($(parse_ints "${target}")) - local digit="${digits[0]}" - digit=$((10#${digit})) - local new_name=$(printf "%0${power}d" "${digit}")"${target#${digits[0]}}" - - # Skip if the same name. - [[ "${target}" = "${new_name}" ]] && return 0 - - # Check that file does not exist. - if [[ -e "${new_name}" ]]; then - _error "${new_name}: File exists!" - return 1 - fi - - mv -- ${target} ${new_name} && echo ${new_name} - } - - _iterate_targets process ${targets[@]} -} - -function _comp_name_parse() { - _autocomplete_first_ls $(find_function | grep ^parse) -} - -complete -o filenames -F _comp_name_parse name_parse diff --git a/module/common/bash/module/Network.nix b/module/common/bash/module/Network.nix new file mode 100644 index 0000000..f284713 --- /dev/null +++ b/module/common/bash/module/Network.nix @@ -0,0 +1,36 @@ +{ ... }: { + text = '' + # Open bluetooth control panel. + function bluetooth() { + blueman-manager + } + + # Open network control panel. + function network() { + nm-connection-editor + } + + # Show active connections. + function nms() { + nmcli connection show + } + + # Start the connection. + # Usage: nu + function nmu() { + nmcli connection up "''${@}" + } + + # Stop the connection. + # Usage: nd + function nmd() { + nmcli connection down "''${@}" + } + + function _complete_connections() { + _autocomplete $(nmcli connection show | sed "1d" | cut -d\ -f1) + } + + complete -F _complete_connections nmd nmu + ''; +} diff --git a/module/common/bash/module/Network.sh b/module/common/bash/module/Network.sh deleted file mode 100644 index bee98b8..0000000 --- a/module/common/bash/module/Network.sh +++ /dev/null @@ -1,32 +0,0 @@ -# Open bluetooth control panel. -function bluetooth() { - blueman-manager -} - -# Open network control panel. -function network() { - nm-connection-editor -} - -# Show active connections. -function nms() { - nmcli connection show -} - -# Start the connection. -# Usage: nu -function nmu() { - nmcli connection up "${@}" -} - -# Stop the connection. -# Usage: nd -function nmd() { - nmcli connection down "${@}" -} - -function _complete_connections() { - _autocomplete $(nmcli connection show | sed "1d" | cut -d\ -f1) -} - -complete -F _complete_connections nmd nmu diff --git a/module/common/bash/module/Nix.nix b/module/common/bash/module/Nix.nix new file mode 100644 index 0000000..11777a7 --- /dev/null +++ b/module/common/bash/module/Nix.nix @@ -0,0 +1,87 @@ +{ ... }: { + text = '' + export _nix_system_config="git+https://git.voronind.com/voronind/nixos.git" + + # Rebuild system. + # Optionally force the hostname. + # Usage: nixos_rebuild [HOSTNAME] + function nixos_rebuild() { + local target="''${1}" + [[ "''${target}" = "" ]] && target="''${HOSTNAME}" + + nixos-rebuild boot --refresh --option eval-cache false --flake "''${_nix_system_config}#''${target}" + } + + # Rebuild and switch system. + # Optionally force the hostname. + # Usage: nixos_switch [HOSTNAME] + function nixos_switch() { + local target="''${1}" + [[ "''${target}" = "" ]] && target="''${HOSTNAME}" + + nixos-rebuild switch --refresh --option eval-cache false --flake "''${_nix_system_config}#''${target}" + } + + # Spawn shell with specified nix environment. + # Uses flake.nix in current dir by default. + # Usage: nix_shell [NAME] + function nix_shell() { + local target="''${1}" + [[ "''${target}" = "" ]] && target="default" + + # Create Nix GC root in .NixRoot{NAME}. + nix build ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" -o ".NixRoot''${target^}" + + NIX_SHELL="''${target}" nix develop ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" + } + alias shell="nix_shell" + + # Spawn temporary nix-shell with specified packages. + # Usage: nix_tmpshell + function nix_tmpshell() { + local IFS=$'\n' + local input=("''${@}") + local pkgs=() + local tag="''${NIX_SHELL}" + + if [[ "''${input}" = "" ]]; then + help nix_tmpshell + return 2 + fi + + [[ "''${tag}" = "" ]] && tag="''${1}" + + for pkg in ''${input[@]}; do + pkgs+=("nixpkgs#''${pkg}") + done + + NIX_SHELL="''${tag}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure ''${pkgs[@]} + } + alias tmpshell="nix_tmpshell" + + # Build live image. + function nixos_live() { + nix build "''${_nix_system_config}#nixosConfigurations.live.config.system.build.isoImage" --refresh ''${@} + } + + # List nixos generations. + function nixos_generations() { + nix-env -p /nix/var/nix/profiles/system --list-generations + } + + # Switch nix-on-droid. + function nixdroid_switch() { + nix-on-droid switch --flake "''${_nix_system_config}" ''${@} + } + + # Autocomplete with available hosts. + function _comp_hosts() { + local IFS=$'\n' + local targets=($(ls ~/.config/linux/system/host/)) + + _autocomplete_first ''${targets[@]} + } + + complete -F _comp_hosts nix_switch nix_rebuild + ''; +} diff --git a/module/common/bash/module/Nix.sh b/module/common/bash/module/Nix.sh deleted file mode 100644 index 01d5e86..0000000 --- a/module/common/bash/module/Nix.sh +++ /dev/null @@ -1,83 +0,0 @@ -export _nix_system_config="git+https://git.voronind.com/voronind/nixos.git" - -# Rebuild system. -# Optionally force the hostname. -# Usage: nixos_rebuild [HOSTNAME] -function nixos_rebuild() { - local target="${1}" - [[ "${target}" = "" ]] && target="${HOSTNAME}" - - nixos-rebuild boot --refresh --option eval-cache false --flake "${_nix_system_config}#${target}" -} - -# Rebuild and switch system. -# Optionally force the hostname. -# Usage: nixos_switch [HOSTNAME] -function nixos_switch() { - local target="${1}" - [[ "${target}" = "" ]] && target="${HOSTNAME}" - - nixos-rebuild switch --refresh --option eval-cache false --flake "${_nix_system_config}#${target}" -} - -# Spawn shell with specified nix environment. -# Uses flake.nix in current dir by default. -# Usage: nix_shell [NAME] -function nix_shell() { - local target="${1}" - [[ "${target}" = "" ]] && target="default" - - # Create Nix GC root in .NixRoot{NAME}. - nix build ".#devShells.${NIX_CURRENT_SYSTEM}.${target}" -o ".NixRoot${target^}" - - NIX_SHELL="${target}" nix develop ".#devShells.${NIX_CURRENT_SYSTEM}.${target}" -} -alias shell="nix_shell" - -# Spawn temporary nix-shell with specified packages. -# Usage: nix_tmpshell -function nix_tmpshell() { - local IFS=$'\n' - local input=("${@}") - local pkgs=() - local tag="${NIX_SHELL}" - - if [[ "${input}" = "" ]]; then - help nix_tmpshell - return 2 - fi - - [[ "${tag}" = "" ]] && tag="${1}" - - for pkg in ${input[@]}; do - pkgs+=("nixpkgs#${pkg}") - done - - NIX_SHELL="${tag}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure ${pkgs[@]} -} -alias tmpshell="nix_tmpshell" - -# Build live image. -function nixos_live() { - nix build "${_nix_system_config}#nixosConfigurations.live.config.system.build.isoImage" --refresh ${@} -} - -# List nixos generations. -function nixos_generations() { - nix-env -p /nix/var/nix/profiles/system --list-generations -} - -# Switch nix-on-droid. -function nixdroid_switch() { - nix-on-droid switch --flake "${_nix_system_config}" ${@} -} - -# Autocomplete with available hosts. -function _comp_hosts() { - local IFS=$'\n' - local targets=($(ls ~/.config/linux/system/host/)) - - _autocomplete_first ${targets[@]} -} - -complete -F _comp_hosts nix_switch nix_rebuild diff --git a/module/common/bash/module/Notify.nix b/module/common/bash/module/Notify.nix new file mode 100644 index 0000000..25cef20 --- /dev/null +++ b/module/common/bash/module/Notify.nix @@ -0,0 +1,15 @@ +{ ... }: { + text = '' + # Send Telegram notification. + # Usage: notify + function notify() { + curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null + } + + # Send silent Telegram notification. + # Usage: notify_silent + function notify_silent() { + curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null + } + ''; +} diff --git a/module/common/bash/module/Notify.sh b/module/common/bash/module/Notify.sh deleted file mode 100644 index ca2ab44..0000000 --- a/module/common/bash/module/Notify.sh +++ /dev/null @@ -1,11 +0,0 @@ -# Send Telegram notification. -# Usage: notify -function notify() { - curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null -} - -# Send silent Telegram notification. -# Usage: notify_silent -function notify_silent() { - curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null -} diff --git a/module/common/bash/module/Own.nix b/module/common/bash/module/Own.nix new file mode 100644 index 0000000..067d9c2 --- /dev/null +++ b/module/common/bash/module/Own.nix @@ -0,0 +1,40 @@ +{ ... }: { + text = '' + # Change file ownership to specified user id and restrict access to him. + # Root user by default. This directory recursively by default. + # Usage: own [USER] [FILES] + function own() { + local IFS=$'\n' + local files=("''${@:2}") + local user="''${1}" + local group="''${1}" + + # default to current dir. + if [ "''${files[*]}" = "" ]; then + files=(".") + fi + + # default to current user. + if [ "''${user}" = "" ]; then + user="''${UID}" + fi + + # If not root, default to users group. + [[ "''${user}" = 0 ]] && group="0" || group="100" + + for file in "''${files[@]}"; do + # set ownership. + chown "''${user}":"''${group}" -R "''${file}" &> /dev/null + + # remove access from group and others. + chmod -077 -R "''${file}" + done + } + + function _complete_own() { + _autocomplete_first_ls $(_get_users) + } + + complete -F _complete_own own + ''; +} diff --git a/module/common/bash/module/Own.sh b/module/common/bash/module/Own.sh deleted file mode 100644 index 05d94da..0000000 --- a/module/common/bash/module/Own.sh +++ /dev/null @@ -1,36 +0,0 @@ -# Change file ownership to specified user id and restrict access to him. -# Root user by default. This directory recursively by default. -# Usage: own [USER] [FILES] -function own() { - local IFS=$'\n' - local files=("${@:2}") - local user="${1}" - local group="${1}" - - # default to current dir. - if [ "${files[*]}" = "" ]; then - files=(".") - fi - - # default to current user. - if [ "${user}" = "" ]; then - user="${UID}" - fi - - # If not root, default to users group. - [[ "${user}" = 0 ]] && group="0" || group="100" - - for file in "${files[@]}"; do - # set ownership. - chown "${user}":"${group}" -R "${file}" &> /dev/null - - # remove access from group and others. - chmod -077 -R "${file}" - done -} - -function _complete_own() { - _autocomplete_first_ls $(_get_users) -} - -complete -F _complete_own own diff --git a/module/common/bash/module/Pack.nix b/module/common/bash/module/Pack.nix new file mode 100644 index 0000000..4c473b7 --- /dev/null +++ b/module/common/bash/module/Pack.nix @@ -0,0 +1,191 @@ +{ ... }: { + text = '' + export _unpack_supported=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$" + + # Pack files into desired format. + # All files and directories by default. + # Usage: pack [FILES] + function pack() { + local IFS=$'\n' + local output="''${1}" + local targets=("''${@:2}") + local format="''${output##*.}" + local name="''${output%.*}" + + # report no output. + if [[ "''${output}" = "" ]]; then + help pack + return 2 + fi + + # report no format. + if [[ "''${format}" = "" ]]; then + _error "Could not determine output format." + help pack + return 2 + fi + + # All targets by default. + [[ "''${targets}" = "" ]] && targets=(*) + + case "''${format}" in + "tgz") + _pack_tgz "''${output}" "''${targets[@]}" + ;; + "txz") + _pack_txz "''${output}" "''${targets[@]}" + ;; + "tar") + _pack_tar "''${output}" "''${targets[@]}" + ;; + "zip") + _pack_zip "''${output}" "''${targets[@]}" + ;; + "gz") + _pack_gz "''${output}" "''${targets[@]}" + ;; + "xz") + _pack_xz "''${output}" "''${targets[@]}" + ;; + "iso") + _pack_iso "''${output}" "''${targets[@]}" + ;; + *) + _error "''${target}: Format not supported." + return 2 + ;; + esac + } + + # Attempt to unpack. + # All supported formats by default. + # Usage: unpack [FILES] + function unpack() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_files | grep -E ''${_unpack_supported})) + + process() { + # unpack file type. + local type="''${target##*.}" + + [[ "''${target}" =~ .tar.gz$ ]] && type="tar.gz" + [[ "''${target}" =~ .tar.xz$ ]] && type="tar.xz" + + # unpack content. + case "''${type,,}" in + "zip") + _unpack_zip "''${target}" + ;; + "7z") + _unpack_7z "''${target}" + ;; + "tgz"|"tar.gz") + _unpack_tgz "''${target}" + ;; + "txz"|"tar.xz") + _unpack_txz "''${target}" + ;; + "tar") + _unpack_tar "''${target}" + ;; + "iso") + _unpack_iso "''${target}" + ;; + "rar") + _unpack_rar "''${target}" + ;; + "xz") + _unpack_xz "''${target}" + ;; + "gz") + _unpack_gz "''${target}" + ;; + *) + _error "''${target}: Format not supported." + return 2 + ;; + esac + } + + _iterate_targets process ''${targets[@]} + } + + function _pack_zip() { + zip -9 -r "''${@}" + } + + function _pack_tgz() { + tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') | gzip -1 > "''${1}" + } + + function _pack_txz() { + tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') | xz -9e > "''${1}" + } + + function _pack_tar() { + tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') > "''${1}" + } + + function _pack_gz() { + pv "''${2}" | gzip -1 > "''${1}" + } + + function _pack_xz() { + pv "''${2}" | xz -9e > "''${1}" + } + + function _pack_iso() { + local input=("''${@:2}") + local output="''${1}" + local args=() + + for arg in ''${input[@]}; do + [[ -d "''${arg}" ]] || { + _error "''${arg} is not a directory." + return 1 + }; + + args+=("''${arg}=''${arg}") + done + + genisoimage -J -r -pad -o "''${output}" -graft-points "''${args[@]}" + } + + function _unpack_zip() { + unzip "''${1}" + } + + function _unpack_7z() { + 7za x "''${1}" + } + + function _unpack_tgz() { + pv "''${1}" | gzip -d | tar -xf - + } + + function _unpack_txz() { + pv "''${1}" | xz -d | tar -xf - + } + + function _unpack_tar() { + pv "''${1}" | tar -xf - + } + + function _unpack_iso() { + 7za x "''${1}" + } + + function _unpack_rar() { + unrar x "''${1}" + } + + function _unpack_gz() { + pv "''${1}" | gzip -d > "''${1%.gz}" + } + + function _unpack_xz() { + pv "''${1}" | xz -d > "''${1%.xz}" + } + ''; +} diff --git a/module/common/bash/module/Pack.sh b/module/common/bash/module/Pack.sh deleted file mode 100644 index f882f29..0000000 --- a/module/common/bash/module/Pack.sh +++ /dev/null @@ -1,187 +0,0 @@ -export _unpack_supported=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$" - -# Pack files into desired format. -# All files and directories by default. -# Usage: pack [FILES] -function pack() { - local IFS=$'\n' - local output="${1}" - local targets=("${@:2}") - local format="${output##*.}" - local name="${output%.*}" - - # report no output. - if [[ "${output}" = "" ]]; then - help pack - return 2 - fi - - # report no format. - if [[ "${format}" = "" ]]; then - _error "Could not determine output format." - help pack - return 2 - fi - - # All targets by default. - [[ "${targets}" = "" ]] && targets=(*) - - case "${format}" in - "tgz") - _pack_tgz "${output}" "${targets[@]}" - ;; - "txz") - _pack_txz "${output}" "${targets[@]}" - ;; - "tar") - _pack_tar "${output}" "${targets[@]}" - ;; - "zip") - _pack_zip "${output}" "${targets[@]}" - ;; - "gz") - _pack_gz "${output}" "${targets[@]}" - ;; - "xz") - _pack_xz "${output}" "${targets[@]}" - ;; - "iso") - _pack_iso "${output}" "${targets[@]}" - ;; - *) - _error "${target}: Format not supported." - return 2 - ;; - esac -} - -# Attempt to unpack. -# All supported formats by default. -# Usage: unpack [FILES] -function unpack() { - local IFS=$'\n' - local targets=(${@}) - [[ "${targets}" = "" ]] && targets=($(_ls_files | grep -E ${_unpack_supported})) - - process() { - # unpack file type. - local type="${target##*.}" - - [[ "${target}" =~ .tar.gz$ ]] && type="tar.gz" - [[ "${target}" =~ .tar.xz$ ]] && type="tar.xz" - - # unpack content. - case "${type,,}" in - "zip") - _unpack_zip "${target}" - ;; - "7z") - _unpack_7z "${target}" - ;; - "tgz"|"tar.gz") - _unpack_tgz "${target}" - ;; - "txz"|"tar.xz") - _unpack_txz "${target}" - ;; - "tar") - _unpack_tar "${target}" - ;; - "iso") - _unpack_iso "${target}" - ;; - "rar") - _unpack_rar "${target}" - ;; - "xz") - _unpack_xz "${target}" - ;; - "gz") - _unpack_gz "${target}" - ;; - *) - _error "${target}: Format not supported." - return 2 - ;; - esac - } - - _iterate_targets process ${targets[@]} -} - -function _pack_zip() { - zip -9 -r "${@}" -} - -function _pack_tgz() { - tar -c "${@:2}" | pv -s $(/usr/bin/env du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | gzip -1 > "${1}" -} - -function _pack_txz() { - tar -c "${@:2}" | pv -s $(/usr/bin/env du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') | xz -9e > "${1}" -} - -function _pack_tar() { - tar -c "${@:2}" | pv -s $(/usr/bin/env du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') > "${1}" -} - -function _pack_gz() { - pv "${2}" | gzip -1 > "${1}" -} - -function _pack_xz() { - pv "${2}" | xz -9e > "${1}" -} - -function _pack_iso() { - local input=("${@:2}") - local output="${1}" - local args=() - - for arg in ${input[@]}; do - [[ -d "${arg}" ]] || { - _error "${arg} is not a directory." - return 1 - }; - - args+=("${arg}=${arg}") - done - - genisoimage -J -r -pad -o "${output}" -graft-points "${args[@]}" -} - -function _unpack_zip() { - unzip "${1}" -} - -function _unpack_7z() { - 7za x "${1}" -} - -function _unpack_tgz() { - pv "${1}" | gzip -d | tar -xf - -} - -function _unpack_txz() { - pv "${1}" | xz -d | tar -xf - -} - -function _unpack_tar() { - pv "${1}" | tar -xf - -} - -function _unpack_iso() { - 7za x "${1}" -} - -function _unpack_rar() { - unrar x "${1}" -} - -function _unpack_gz() { - pv "${1}" | gzip -d > "${1%.gz}" -} - -function _unpack_xz() { - pv "${1}" | xz -d > "${1%.xz}" -} diff --git a/module/common/bash/module/Parse.nix b/module/common/bash/module/Parse.nix new file mode 100644 index 0000000..c201cc2 --- /dev/null +++ b/module/common/bash/module/Parse.nix @@ -0,0 +1,171 @@ +{ ... }: { + text = '' + _PARSE_ALLOWED_CHARS="_-" + _PARSE_SPLIT_CHARS="\.\ _-" + + # Parse data and output simplified format. + # Usage: parse_simple + function parse_simple() { + echo "''${*}" | sed \ + -e "s/[''${_PARSE_SPLIT_CHARS}]/_/g" \ + -e "s/[^[:alnum:]''${_PARSE_ALLOWED_CHARS}]//g" \ + -e "s/_\+/_/g" -e "s/-\+/-/g" \ + -e "s/_-/_/g" -e "s/-_/_/g" \ + -e "s/_\+/_/g" \ + -e "s/^_//" -e "s/_$//" + } + + # Parse to PascalCase. + # Usage: parse_pascal + function parse_pascal() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result + + for part in "''${parts[@]}"; do + local word="''${part,,}" + word="''${word^}" + result="''${result}''${word}" + done + + echo "''${result}" + } + + # Parse to snake_case. + # Usage: parse_snake + function parse_snake() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result + + for part in "''${parts[@]}"; do + local word="''${part,,}" + result="''${result}_''${word}" + done + + echo "''${result#_}" + } + + # Parse to kebab-case. + # Usage: parse_kebab + function parse_kebab() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result + + for part in "''${parts[@]}"; do + local word="''${part,,}" + result="''${result}-''${word}" + done + + echo "''${result#-}" + } + + # Parse to camelCase. + # Usage: parse_camel + function parse_camel() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result + + for part in "''${parts[@]}"; do + local word="''${part,,}" + word="''${word^}" + result="''${result}''${word}" + done + + echo "''${result,}" + } + + # Parse to SNAKE_CASE_UPPERCASE. **NOT STABLE! Repeating results in different output.** + # Usage: parse_snake_uppercase + function parse_snake_uppercase() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result + + for part in "''${parts[@]}"; do + local word="''${part^^}" + result="''${result}_''${word}" + done + + echo "''${result#_}" + } + + # Parse data keeping only alphanumeric characters. + # Usage: parse_alnum + function parse_alnum() { + echo "''${*}" | sed -e "s/[^[:alnum:]]//g" + } + + # Parse integers from mixed string. + # Usage: parse_ints + function parse_ints() { + echo "''${*}" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g' + } + + # Parse string to lowercase. + # Usage: parse_lowercase + function parse_lowercase() { + echo "''${*,,}" + } + + # Parse string to uppercase. + # Usage: parse_uppercase + function parse_uppercase() { + echo "''${*^^}" + } + + # Parse string to title case. + # Usage: parse_titlecase + function parse_titlecase() { + local IFS=$'\n' + local parts=($(_parse_split ''${@})) + local minors=("is" "at" "of" "to" "in" "for" "the" "a" "an" "and" "but" "or" "on" "was" "were" "been" "be" "do" "did" "does") + + echo -n "$(parse_sentencecase ''${parts[0]})" + for part in ''${parts[@]:1}; do + if _contains $(echo ''${part,,} | sed -e "s/[''${_PARSE_SPLIT_CHARS}]//g") ''${minors[@]}; then + echo -n "''${part,,}" + else + echo -n "$(parse_sentencecase ''${part})" + fi + done + + echo + } + + # Parse string to sentence case. + # Usage: parse_sentencecase + function parse_sentencecase() { + local lower="''${*,,}" + echo "''${lower^}" + } + + # Parse string to start case. + # Usage: parse_startcase + function parse_startcase() { + local IFS=$'\n' + local parts=($(_parse_split ''${*})) + + for part in ''${parts[@]}; do + echo -n "''${part^}" + done + + echo + } + + # Parse string to pretty Json. + # Usage: parse_json + function parse_json() { + echo "''${*}" | jq + } + + # Split string by separators. + # Usage: _parse_split + function _parse_split() { + echo "''${*}" | sed -e "s/[A-Z]\+/\n&/g" -e "s/[0-9]\+/\n&\n/g" -e "s/[''${_PARSE_SPLIT_CHARS}]/&\n/g" | sed -e "/^$/d" + } + + # Get name parts. + # Usage: _get_parts + function _get_parts() { + _parse_split "''${*}" | sed -e "s/[''${_PARSE_SPLIT_CHARS}]//g" | sed -e "/^$/d" + } + ''; +} diff --git a/module/common/bash/module/Parse.sh b/module/common/bash/module/Parse.sh deleted file mode 100644 index 6db05e9..0000000 --- a/module/common/bash/module/Parse.sh +++ /dev/null @@ -1,167 +0,0 @@ -_PARSE_ALLOWED_CHARS="_-" -_PARSE_SPLIT_CHARS="\.\ _-" - -# Parse data and output simplified format. -# Usage: parse_simple -function parse_simple() { - echo "${*}" | sed \ - -e "s/[${_PARSE_SPLIT_CHARS}]/_/g" \ - -e "s/[^[:alnum:]${_PARSE_ALLOWED_CHARS}]//g" \ - -e "s/_\+/_/g" -e "s/-\+/-/g" \ - -e "s/_-/_/g" -e "s/-_/_/g" \ - -e "s/_\+/_/g" \ - -e "s/^_//" -e "s/_$//" -} - -# Parse to PascalCase. -# Usage: parse_pascal -function parse_pascal() { - local parts=($(_get_parts $(parse_simple "${*}"))) - local result - - for part in "${parts[@]}"; do - local word="${part,,}" - word="${word^}" - result="${result}${word}" - done - - echo "${result}" -} - -# Parse to snake_case. -# Usage: parse_snake -function parse_snake() { - local parts=($(_get_parts $(parse_simple "${*}"))) - local result - - for part in "${parts[@]}"; do - local word="${part,,}" - result="${result}_${word}" - done - - echo "${result#_}" -} - -# Parse to kebab-case. -# Usage: parse_kebab -function parse_kebab() { - local parts=($(_get_parts $(parse_simple "${*}"))) - local result - - for part in "${parts[@]}"; do - local word="${part,,}" - result="${result}-${word}" - done - - echo "${result#-}" -} - -# Parse to camelCase. -# Usage: parse_camel -function parse_camel() { - local parts=($(_get_parts $(parse_simple "${*}"))) - local result - - for part in "${parts[@]}"; do - local word="${part,,}" - word="${word^}" - result="${result}${word}" - done - - echo "${result,}" -} - -# Parse to SNAKE_CASE_UPPERCASE. **NOT STABLE! Repeating results in different output.** -# Usage: parse_snake_uppercase -function parse_snake_uppercase() { - local parts=($(_get_parts $(parse_simple "${*}"))) - local result - - for part in "${parts[@]}"; do - local word="${part^^}" - result="${result}_${word}" - done - - echo "${result#_}" -} - -# Parse data keeping only alphanumeric characters. -# Usage: parse_alnum -function parse_alnum() { - echo "${*}" | sed -e "s/[^[:alnum:]]//g" -} - -# Parse integers from mixed string. -# Usage: parse_ints -function parse_ints() { - echo "${*}" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g' -} - -# Parse string to lowercase. -# Usage: parse_lowercase -function parse_lowercase() { - echo "${*,,}" -} - -# Parse string to uppercase. -# Usage: parse_uppercase -function parse_uppercase() { - echo "${*^^}" -} - -# Parse string to title case. -# Usage: parse_titlecase -function parse_titlecase() { - local IFS=$'\n' - local parts=($(_parse_split ${@})) - local minors=("is" "at" "of" "to" "in" "for" "the" "a" "an" "and" "but" "or" "on" "was" "were" "been" "be" "do" "did" "does") - - echo -n "$(parse_sentencecase ${parts[0]})" - for part in ${parts[@]:1}; do - if _contains $(echo ${part,,} | sed -e "s/[${_PARSE_SPLIT_CHARS}]//g") ${minors[@]}; then - echo -n "${part,,}" - else - echo -n "$(parse_sentencecase ${part})" - fi - done - - echo -} - -# Parse string to sentence case. -# Usage: parse_sentencecase -function parse_sentencecase() { - local lower="${*,,}" - echo "${lower^}" -} - -# Parse string to start case. -# Usage: parse_startcase -function parse_startcase() { - local IFS=$'\n' - local parts=($(_parse_split ${*})) - - for part in ${parts[@]}; do - echo -n "${part^}" - done - - echo -} - -# Parse string to pretty Json. -# Usage: parse_json -function parse_json() { - echo "${*}" | jq -} - -# Split string by separators. -# Usage: _parse_split -function _parse_split() { - echo "${*}" | sed -e "s/[A-Z]\+/\n&/g" -e "s/[0-9]\+/\n&\n/g" -e "s/[${_PARSE_SPLIT_CHARS}]/&\n/g" | sed -e "/^$/d" -} - -# Get name parts. -# Usage: _get_parts -function _get_parts() { - _parse_split "${*}" | sed -e "s/[${_PARSE_SPLIT_CHARS}]//g" | sed -e "/^$/d" -} diff --git a/module/common/bash/module/Permission.nix b/module/common/bash/module/Permission.nix new file mode 100644 index 0000000..3b785c1 --- /dev/null +++ b/module/common/bash/module/Permission.nix @@ -0,0 +1,13 @@ +{ ... }: { + text = '' + # Recursively change permissions to allow read sharing with group and others. + function perm_share() { + find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \; + } + + # Recursively change permissions to restrict access for group and others. + function perm() { + find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \; + } + ''; +} diff --git a/module/common/bash/module/Permission.sh b/module/common/bash/module/Permission.sh deleted file mode 100644 index 7d2bd24..0000000 --- a/module/common/bash/module/Permission.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Recursively change permissions to allow read sharing with group and others. -function perm_share() { - find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \; -} - -# Recursively change permissions to restrict access for group and others. -function perm() { - find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \; -} diff --git a/module/common/bash/module/Power.nix b/module/common/bash/module/Power.nix new file mode 100644 index 0000000..54026d0 --- /dev/null +++ b/module/common/bash/module/Power.nix @@ -0,0 +1,13 @@ +{ ... }: { + text = '' + # Suspend system. + function slp() { + systemctl suspend -i + } + + # Poweroff. + function bye() { + systemctl poweroff -i + } + ''; +} diff --git a/module/common/bash/module/Power.sh b/module/common/bash/module/Power.sh deleted file mode 100644 index 0b25944..0000000 --- a/module/common/bash/module/Power.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Suspend system. -function slp() { - systemctl suspend -i -} - -# Poweroff. -function bye() { - systemctl poweroff -i -} diff --git a/module/common/bash/module/Prune.nix b/module/common/bash/module/Prune.nix new file mode 100644 index 0000000..8a5133d --- /dev/null +++ b/module/common/bash/module/Prune.nix @@ -0,0 +1,28 @@ +{ ... }: { + text = '' + export _flatpakcfg_path="''${HOME}/.config/linux/Flatpak.txt" + + # Prune everything unused in docker. + function prune_docker() { + docker system prune --volumes --all + } + + # Prune Nix Store. + function prune_nix() { + nix-store --gc + } + + # Uninstall flatpaks not listed in the config. + function prune_flatpak() { + local IFS=$'\n' + local config=($(cat ''${_flatpakcfg_path} | cut -f2)) + local installed=($(flatpak list --app | cut -f2)) + + process() { + _contains ''${target} ''${config[@]} || flatpak uninstall ''${target} + } + + _iterate_targets process ''${installed[@]} + } + ''; +} diff --git a/module/common/bash/module/Prune.sh b/module/common/bash/module/Prune.sh deleted file mode 100644 index 561ee2b..0000000 --- a/module/common/bash/module/Prune.sh +++ /dev/null @@ -1,24 +0,0 @@ -export _flatpakcfg_path="${HOME}/.config/linux/Flatpak.txt" - -# Prune everything unused in docker. -function prune_docker() { - docker system prune --volumes --all -} - -# Prune Nix Store. -function prune_nix() { - nix-store --gc -} - -# Uninstall flatpaks not listed in the config. -function prune_flatpak() { - local IFS=$'\n' - local config=($(cat ${_flatpakcfg_path} | cut -f2)) - local installed=($(flatpak list --app | cut -f2)) - - process() { - _contains ${target} ${config[@]} || flatpak uninstall ${target} - } - - _iterate_targets process ${installed[@]} -} diff --git a/module/common/bash/module/Ps.nix b/module/common/bash/module/Ps.nix new file mode 100644 index 0000000..bc4fa8b --- /dev/null +++ b/module/common/bash/module/Ps.nix @@ -0,0 +1,15 @@ +{ ... }: { + text = '' + # Find process and filter. + # Usage: fps [PROCESS] + function fps() { + local process="''${1}" + + if [[ "''${process}" = "" ]]; then + ps aux + else + ps aux | sed -n -e "1p" -e "/''${process}/Ip" | sed -e "/sed -n -e 1p -e/d" + fi + } + ''; +} diff --git a/module/common/bash/module/Ps.sh b/module/common/bash/module/Ps.sh deleted file mode 100644 index 0cf995b..0000000 --- a/module/common/bash/module/Ps.sh +++ /dev/null @@ -1,11 +0,0 @@ -# Find process and filter. -# Usage: fps [PROCESS] -function fps() { - local process="${1}" - - if [[ "${process}" = "" ]]; then - ps aux - else - ps aux | sed -n -e "1p" -e "/${process}/Ip" | sed -e "/sed -n -e 1p -e/d" - fi -} diff --git a/module/common/bash/module/Ps1.nix b/module/common/bash/module/Ps1.nix new file mode 100644 index 0000000..34a16c0 --- /dev/null +++ b/module/common/bash/module/Ps1.nix @@ -0,0 +1,157 @@ +{ style, ... }: let + accent = "${style.color.accent-r};${style.color.accent-g};${style.color.accent-b};"; + negative = "${style.color.negative-r};${style.color.negative-g};${style.color.negative-b};"; + neutral = "${style.color.neutral-r};${style.color.neutral-g};${style.color.neutral-b};"; + positive = "${style.color.positive-r};${style.color.positive-g};${style.color.positive-b};"; +in { + text = '' + export PROMPT_COMMAND=(__prompt_command "''${PROMPT_COMMAND[@]}") + + function __prompt_color() { + local color="''${1}" + if [[ "''${color}" = "" ]]; then + printf "\[\x1b[0m\]" + else + printf "\[\x1b[38;2;''${color}m\]" + fi + } + + # Custom terminal prompt format. + function __prompt_command() { + local last_status="''${?}" + local is_error=false + local is_root=false + + if [[ ''${last_status} != 0 && ''${last_status} != 130 ]]; then + is_error=true + fi + if [[ "''${UID}" -eq 0 ]]; then + is_root=true + fi + + # Add newline. + PS1="\n" + + # Set error red. + if ''${is_error}; then + PS1+="$(__prompt_color '${negative}')" + PS1+="[" + else + PS1+="$(__prompt_color)" + PS1+="[" + fi + + # Add time. + # PS1+="$(__prompt_color '${accent}')" + # PS1+="$(date +%H:%M) " + + # Set root red. + if ''${is_root}; then + PS1+="$(__prompt_color '${negative}')" + else + PS1+="$(__prompt_color '${neutral}')" + fi + + # Add user, host and working dir. + PS1+="\u@\h " + PS1+="$(__prompt_color '${positive}')" + PS1+="\w" + # PS1+="\''${PWD}" + + # Add git branch if available. + local git_branch="$(_git_current_branch)" + if [[ "''${git_branch}" != "" ]]; then + PS1+=" $(__prompt_color '${accent}')@''${git_branch}" + fi + + # Set error red. + if ''${is_error}; then + PS1+="$(__prompt_color '${negative}')" + PS1+="] " + else + PS1+="$(__prompt_color)" + PS1+="] " + fi + + # If error, show code. + if ''${is_error}; then + PS1+="$(__prompt_color '${negative}')(" + PS1+="''${last_status}" + local error_type="$(_ps1error ''${last_status})" + [[ "''${error_type}" != "" ]] && PS1+=" ''${error_type}" + PS1+=")$(__prompt_color) " + fi + + # Command on new line. + PS1+="\n" + + # Show nix shell name. + if [ -n "''${NIX_SHELL}" ]; then + PS1+="''${NIX_SHELL} " + fi + + # Show remote connections. + if [ -n "''${SSH_TTY}" ]; then + PS1+=">" + fi + + PS1+="$(__prompt_color)" + + # Set user tag. + if ''${is_root}; then + PS1+="# " + else + PS1+="$ " + fi + + # Reset color. + PS1+="\[\033[0m\]" + } + + # Convert error code into short description. + # Usage: _ps1error + function _ps1error() { + local type + case ''${1} in + 1) type="GENERAL" ;; + 2) type="MISUSE" ;; + 126) type="CANTEXEC" ;; + 127) type="CMDNF" ;; + 129) type="SIGHUP" ;; + 130) type="SIGINT" ;; + 131) type="SIGQUIT" ;; + 132) type="SIGILL" ;; + 133) type="SIGTRAP" ;; + 134) type="SIGABRT" ;; + 135) type="SIGBUS" ;; + 136) type="SIGFPE" ;; + 137) type="SIGKILL" ;; + 138) type="SIGUSR1" ;; + 139) type="SIGSEGV" ;; + 140) type="SIGUSR2" ;; + 141) type="SIGPIPE" ;; + 142) type="SIGALRM" ;; + 143) type="SIGTERM" ;; + 144) type="" ;; + 145) type="SIGCHLD" ;; + 146) type="SIGCONT" ;; + 147) type="SIGSTOP" ;; + 148) type="SIGTSTP" ;; + 149) type="SIGTTIN" ;; + 150) type="SIGTTOU" ;; + 151) type="SIGURG" ;; + 152) type="SIGXCPU" ;; + 153) type="SIGXFSZ" ;; + 154) type="SIGVTALRM" ;; + 155) type="SIGPROF" ;; + 156) type="SIGWINCH" ;; + 157) type="SIGIO" ;; + 158) type="SIGPWR" ;; + 159) type="SIGSYS" ;; + *) type="" ;; + esac + + echo -n "''${type}" + } + ''; +} diff --git a/module/common/bash/module/Ps1.sh b/module/common/bash/module/Ps1.sh deleted file mode 100644 index 70165af..0000000 --- a/module/common/bash/module/Ps1.sh +++ /dev/null @@ -1,151 +0,0 @@ -export PROMPT_COMMAND=(__prompt_command "${PROMPT_COMMAND[@]}") - -function __prompt_color() { - local color="${1}" - if [[ "${color}" = "" ]]; then - printf "\[\x1b[0m\]" - else - printf "\[\x1b[38;2;${color}m\]" - fi - # echo "\[\033[48;5;${COLOR_BACKGROUND};38;5;${color}m\]" # With backgroud. - # echo "\[\033[38;5;${color}m\]" # Only foreground. -} - -# Custom terminal prompt format. -function __prompt_command() { - local last_status="${?}" - local is_error=false - local is_root=false - - if [[ ${last_status} != 0 && ${last_status} != 130 ]]; then - is_error=true - fi - if [[ "${UID}" -eq 0 ]]; then - is_root=true - fi - - # Add newline. - PS1="\n" - - # Set error red. - if ${is_error}; then - PS1+="$(__prompt_color ${negative_rgb})" - PS1+="[" - else - PS1+="$(__prompt_color)" - PS1+="[" - fi - - # Add time. - # PS1+="$(__prompt_color ${accent_rgb})" - # PS1+="$(date +%H:%M) " - - # Set root red. - if ${is_root}; then - PS1+="$(__prompt_color ${negative_rgb})" - else - PS1+="$(__prompt_color ${neutral_rgb})" - fi - - # Add user, host and working dir. - PS1+="\u@\h " - PS1+="$(__prompt_color ${positive_rgb})" - PS1+="\w" - # PS1+="\${PWD}" - - # Add git branch if available. - local git_branch="$(_git_current_branch)" - if [[ "${git_branch}" != "" ]]; then - PS1+=" $(__prompt_color ${accent_rgb})@${git_branch}" - fi - - # Set error red. - if ${is_error}; then - PS1+="$(__prompt_color ${negative_rgb})" - PS1+="] " - else - PS1+="$(__prompt_color)" - PS1+="] " - fi - - # If error, show code. - if ${is_error}; then - PS1+="$(__prompt_color ${negative_rgb})(" - PS1+="${last_status}" - local error_type="$(_ps1error ${last_status})" - [[ "${error_type}" != "" ]] && PS1+=" ${error_type}" - PS1+=")$(__prompt_color) " - fi - - # Command on new line. - PS1+="\n" - PS1+="$(__prompt_color ${fg_3_rgb})" - - # Show nix shell name. - if [ -n "${NIX_SHELL}" ]; then - PS1+="${NIX_SHELL} " - fi - - # Show remote connections. - if [ -n "${SSH_TTY}" ]; then - PS1+=">" - fi - - PS1+="$(__prompt_color)" - - # Set user tag. - if ${is_root}; then - PS1+="# " - else - PS1+="$ " - fi - - # Reset color. - PS1+="\[\033[0m\]" -} - -# Convert error code into short description. -# Usage: _ps1error -function _ps1error() { - local type - case ${1} in - 1) type="GENERAL" ;; - 2) type="MISUSE" ;; - 126) type="CANTEXEC" ;; - 127) type="CMDNF" ;; - 129) type="SIGHUP" ;; - 130) type="SIGINT" ;; - 131) type="SIGQUIT" ;; - 132) type="SIGILL" ;; - 133) type="SIGTRAP" ;; - 134) type="SIGABRT" ;; - 135) type="SIGBUS" ;; - 136) type="SIGFPE" ;; - 137) type="SIGKILL" ;; - 138) type="SIGUSR1" ;; - 139) type="SIGSEGV" ;; - 140) type="SIGUSR2" ;; - 141) type="SIGPIPE" ;; - 142) type="SIGALRM" ;; - 143) type="SIGTERM" ;; - 144) type="" ;; - 145) type="SIGCHLD" ;; - 146) type="SIGCONT" ;; - 147) type="SIGSTOP" ;; - 148) type="SIGTSTP" ;; - 149) type="SIGTTIN" ;; - 150) type="SIGTTOU" ;; - 151) type="SIGURG" ;; - 152) type="SIGXCPU" ;; - 153) type="SIGXFSZ" ;; - 154) type="SIGVTALRM" ;; - 155) type="SIGPROF" ;; - 156) type="SIGWINCH" ;; - 157) type="SIGIO" ;; - 158) type="SIGPWR" ;; - 159) type="SIGSYS" ;; - *) type="" ;; - esac - - echo -n "${type}" -} diff --git a/module/common/bash/module/Random.nix b/module/common/bash/module/Random.nix new file mode 100644 index 0000000..8346d43 --- /dev/null +++ b/module/common/bash/module/Random.nix @@ -0,0 +1,14 @@ +{ ... }: { + text = '' + # Picks a random file or directory. + function random_file() { + local IFS=$'\n' + local dirs=($(ls)) + local total=''${#dirs[@]} + ((total--)) + local index=$(shuf -i 0-''${total} -n 1) + + echo ''${dirs[$index]} + } + ''; +} diff --git a/module/common/bash/module/Random.sh b/module/common/bash/module/Random.sh deleted file mode 100644 index 2162f62..0000000 --- a/module/common/bash/module/Random.sh +++ /dev/null @@ -1,10 +0,0 @@ -# Picks a random file or directory. -function random_file() { - local IFS=$'\n' - local dirs=($(ls)) - local total=${#dirs[@]} - ((total--)) - local index=$(shuf -i 0-${total} -n 1) - - echo ${dirs[$index]} -} diff --git a/module/common/bash/module/Recursive.nix b/module/common/bash/module/Recursive.nix new file mode 100644 index 0000000..38419fa --- /dev/null +++ b/module/common/bash/module/Recursive.nix @@ -0,0 +1,84 @@ +{ ... }: { + text = '' + # Run something recursively over all directories. + # Usage: recursive + function recursive() { + if [[ "''${*}" = "" ]]; then + help recursive + return 2 + fi + + local IFS=$'\n' + local current="''${PWD}" + local dirs=$(find -type d) + local total=$(find -type d | wc -l) # TODO: don't call find twice. won't work with "echo ''${dirs}". + local count=0 + local failed=0 + + for dir in ''${dirs}; do + # increment counter. + ((count++)) + + # cd into the next dir. + cd "''${current}" || failed=''${?} + cd "''${dir}" || failed=''${?} + + # echo status. + echo -e "''${color_bblue}[''${count}/''${total}] ''${dir}''${color_default}" + + # run command. + ''${*} || failed=''${?} + + # Add newline if not the last one. + [[ "''${count}" = "''${total}" ]] || echo + done + + # return back on complete. + cd "''${current}" || failed=''${?} + + return ''${failed} + } + + # Run something recursively over directories of 1 depth (excluding current dir). + # Usage: recursive1 + function recursive1() { + if [[ "''${*}" = "" ]]; then + help recursive1 + return 2 + fi + + local IFS=$'\n' + local current="''${PWD}" + local dirs=$(find -mindepth 1 -maxdepth 1 -type d) + local total=$(find -mindepth 1 -maxdepth 1 -type d | wc -l) # TODO: don't call find twice. won't work with "echo ''${dirs}". + local count=0 + local failed=0 + + for dir in ''${dirs}; do + # increment counter. + ((count++)) + + # cd into the next dir. + cd "''${current}" + cd "''${dir}" + + # echo status. + echo -e "''${color_bblue}[''${count}/''${total}] ''${dir}''${color_default}" + + # run command. + ''${*} || failed=''${?} + + # Add newline if not the last one. + [[ "''${count}" = "''${total}" ]] || echo + done + + # return back on complete. + cd "''${current}" + + return ''${failed} + } + + # autocomplete. + complete -F _autocomplete_nested recursive recursive1 + ''; +} diff --git a/module/common/bash/module/Recursive.sh b/module/common/bash/module/Recursive.sh deleted file mode 100644 index 91c071c..0000000 --- a/module/common/bash/module/Recursive.sh +++ /dev/null @@ -1,80 +0,0 @@ -# Run something recursively over all directories. -# Usage: recursive -function recursive() { - if [[ "${*}" = "" ]]; then - help recursive - return 2 - fi - - local IFS=$'\n' - local current="${PWD}" - local dirs=$(find -type d) - local total=$(find -type d | wc -l) # TODO: don't call find twice. won't work with "echo ${dirs}". - local count=0 - local failed=0 - - for dir in ${dirs}; do - # increment counter. - ((count++)) - - # cd into the next dir. - cd "${current}" || failed=${?} - cd "${dir}" || failed=${?} - - # echo status. - echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}" - - # run command. - ${*} || failed=${?} - - # Add newline if not the last one. - [[ "${count}" = "${total}" ]] || echo - done - - # return back on complete. - cd "${current}" || failed=${?} - - return ${failed} -} - -# Run something recursively over directories of 1 depth (excluding current dir). -# Usage: recursive1 -function recursive1() { - if [[ "${*}" = "" ]]; then - help recursive1 - return 2 - fi - - local IFS=$'\n' - local current="${PWD}" - local dirs=$(find -mindepth 1 -maxdepth 1 -type d) - local total=$(find -mindepth 1 -maxdepth 1 -type d | wc -l) # TODO: don't call find twice. won't work with "echo ${dirs}". - local count=0 - local failed=0 - - for dir in ${dirs}; do - # increment counter. - ((count++)) - - # cd into the next dir. - cd "${current}" - cd "${dir}" - - # echo status. - echo -e "${color_bblue}[${count}/${total}] ${dir}${color_default}" - - # run command. - ${*} || failed=${?} - - # Add newline if not the last one. - [[ "${count}" = "${total}" ]] || echo - done - - # return back on complete. - cd "${current}" - - return ${failed} -} - -# autocomplete. -complete -F _autocomplete_nested recursive recursive1 diff --git a/module/common/bash/module/Save.nix b/module/common/bash/module/Save.nix new file mode 100644 index 0000000..64e9a24 --- /dev/null +++ b/module/common/bash/module/Save.nix @@ -0,0 +1,23 @@ +{ ... }: { + text = '' + # Backup a game save. + # Usage: save [TARGETS] + function save() { + local IFS=$'\n' + local targets=("''${@}") + local files=() + [[ "''${targets}" = "" ]] && targets=($(_ls_dir)) + + _info "Archiving..." + for target in ''${targets[@]}; do + files+=($(archive "''${target}")) + done + + _info "Uploading..." + try sudo rcp "''${files[@]}" home:/storage/cold_1/backup/save/ + + _info "Cleaning..." + archive_prune 2> /dev/null + } + ''; +} diff --git a/module/common/bash/module/Save.sh b/module/common/bash/module/Save.sh deleted file mode 100644 index 6b1e7f0..0000000 --- a/module/common/bash/module/Save.sh +++ /dev/null @@ -1,19 +0,0 @@ -# Backup a game save. -# Usage: save [TARGETS] -function save() { - local IFS=$'\n' - local targets=("${@}") - local files=() - [[ "${targets}" = "" ]] && targets=($(_ls_dir)) - - _info "Archiving..." - for target in ${targets[@]}; do - files+=($(archive "${target}")) - done - - _info "Uploading..." - try sudo rcp "${files[@]}" home:/storage/cold_1/backup/save/ - - _info "Cleaning..." - archive_prune 2> /dev/null -} diff --git a/module/common/bash/module/Shopt.nix b/module/common/bash/module/Shopt.nix new file mode 100644 index 0000000..4760280 --- /dev/null +++ b/module/common/bash/module/Shopt.nix @@ -0,0 +1,27 @@ +{ ... }: { + text = '' + shopt -s dotglob + shopt -s globstar + shopt -s autocd + shopt -s extglob + + # Enable vim mode. + bind 'set editing-mode vi' + bind 'set show-mode-in-prompt on' + bind 'set keyseq-timeout 0' + + # Set the mode string and cursor to indicate the vim mode + # For the number after `\e[`: + # 0: blinking block + # 1: blinking block (default) + # 2: steady block + # 3: blinking underline + # 4: steady underline + # 5: blinking bar (xterm) + # 6: steady bar (xterm) + bind 'set vi-ins-mode-string \1\e[6 q\2' + bind 'set vi-cmd-mode-string \1\e[2 q\2' + + exec {BASH_XTRACEFD}>/dev/null + ''; +} diff --git a/module/common/bash/module/Shopt.sh b/module/common/bash/module/Shopt.sh deleted file mode 100644 index 6448441..0000000 --- a/module/common/bash/module/Shopt.sh +++ /dev/null @@ -1,23 +0,0 @@ -shopt -s dotglob -shopt -s globstar -shopt -s autocd -shopt -s extglob - -# Enable vim mode. -bind 'set editing-mode vi' -bind 'set show-mode-in-prompt on' -bind 'set keyseq-timeout 0' - -# Set the mode string and cursor to indicate the vim mode -# For the number after `\e[`: -# 0: blinking block -# 1: blinking block (default) -# 2: steady block -# 3: blinking underline -# 4: steady underline -# 5: blinking bar (xterm) -# 6: steady bar (xterm) -bind 'set vi-ins-mode-string \1\e[6 q\2' -bind 'set vi-cmd-mode-string \1\e[2 q\2' - -exec {BASH_XTRACEFD}>/dev/null diff --git a/module/common/bash/module/Sound.nix b/module/common/bash/module/Sound.nix new file mode 100644 index 0000000..f2ca639 --- /dev/null +++ b/module/common/bash/module/Sound.nix @@ -0,0 +1,8 @@ +{ ... }: { + text = '' + # Open a sound control panel. + function sound() { + pavucontrol + } + ''; +} diff --git a/module/common/bash/module/Sound.sh b/module/common/bash/module/Sound.sh deleted file mode 100644 index 8b5d9bd..0000000 --- a/module/common/bash/module/Sound.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Open a sound control panel. -function sound() { - pavucontrol -} diff --git a/module/common/bash/module/Ssh.nix b/module/common/bash/module/Ssh.nix new file mode 100644 index 0000000..19663ec --- /dev/null +++ b/module/common/bash/module/Ssh.nix @@ -0,0 +1,22 @@ +{ ... }: { + text = '' + # Mount FS over ssh. Just extra config for sshfs. + # Usage: ssh_mount + function ssh_mount() { + sshfs -o uid=1000,auto_unmount,allow_other "''${@}" + } + + # Mount FS over ssh. Just extra config for sshfs. + # Usage: ssh_mount + function ssh_mount_ro() { + sshfs -o uid=1000,auto_unmount,allow_other,ro "''${@}" + } + + # Generate private an public keys on a local host and print a public key. + function ssh_keygen() { + ssh-keygen && cat ~/.ssh/*.pub + } + + complete -o nospace -F _sshfs sshmount + ''; +} diff --git a/module/common/bash/module/Ssh.sh b/module/common/bash/module/Ssh.sh deleted file mode 100644 index 237dc16..0000000 --- a/module/common/bash/module/Ssh.sh +++ /dev/null @@ -1,18 +0,0 @@ -# Mount FS over ssh. Just extra config for sshfs. -# Usage: ssh_mount -function ssh_mount() { - sshfs -o uid=1000,auto_unmount,allow_other "${@}" -} - -# Mount FS over ssh. Just extra config for sshfs. -# Usage: ssh_mount -function ssh_mount_ro() { - sshfs -o uid=1000,auto_unmount,allow_other,ro "${@}" -} - -# Generate private an public keys on a local host and print a public key. -function ssh_keygen() { - ssh-keygen && cat ~/.ssh/*.pub -} - -complete -o nospace -F _sshfs sshmount diff --git a/module/common/bash/module/Steam.nix b/module/common/bash/module/Steam.nix new file mode 100644 index 0000000..381d09d --- /dev/null +++ b/module/common/bash/module/Steam.nix @@ -0,0 +1,8 @@ +{ ... }: { + text = '' + # Start Steam with Wayland screen share for Link to work. + function steam_link() { + steam -pipewire -pipewire-dmabuf + } + ''; +} diff --git a/module/common/bash/module/Steam.sh b/module/common/bash/module/Steam.sh deleted file mode 100644 index d48aedc..0000000 --- a/module/common/bash/module/Steam.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Start Steam with Wayland screen share for Link to work. -function steam_link() { - steam -pipewire -pipewire-dmabuf -} diff --git a/module/common/bash/module/Su.nix b/module/common/bash/module/Su.nix new file mode 100644 index 0000000..da22516 --- /dev/null +++ b/module/common/bash/module/Su.nix @@ -0,0 +1,28 @@ +{ ... }: { + text = '' + # Su shortcut for lazy me. + # Root by default. + # Usage: s [USER] + function s() { + su - ''${1} + } + + # Run something as root. Runs command as a current user if su is not available. + # Usage: sudo + function sudo() { + if command -v su &> /dev/null; then + su -c "$(echo ''${*} | tr '\n' ' ')" + else + ''${*} + fi + + } + + function _complete_s() { + _autocomplete_first $(_get_users) + } + + complete -F _complete_s s + complete -F _autocomplete_nested sudo + ''; +} diff --git a/module/common/bash/module/Su.sh b/module/common/bash/module/Su.sh deleted file mode 100644 index b8d21e4..0000000 --- a/module/common/bash/module/Su.sh +++ /dev/null @@ -1,24 +0,0 @@ -# Su shortcut for lazy me. -# Root by default. -# Usage: s [USER] -function s() { - su - ${1} -} - -# Run something as root. Runs command as a current user if su is not available. -# Usage: sudo -function sudo() { - if command -v su &> /dev/null; then - su -c "$(echo ${*} | tr '\n' ' ')" - else - ${*} - fi - -} - -function _complete_s() { - _autocomplete_first $(_get_users) -} - -complete -F _complete_s s -complete -F _autocomplete_nested sudo diff --git a/module/common/bash/module/Terminal.nix b/module/common/bash/module/Terminal.nix new file mode 100644 index 0000000..e833edc --- /dev/null +++ b/module/common/bash/module/Terminal.nix @@ -0,0 +1,10 @@ +{ ... }: { + text = '' + # Get terminal size. + function tsize() { + local width=$(tput cols) + local height=$(tput lines) + echo "''${width}x''${height}" + } + ''; +} diff --git a/module/common/bash/module/Terminal.sh b/module/common/bash/module/Terminal.sh deleted file mode 100644 index e7ddace..0000000 --- a/module/common/bash/module/Terminal.sh +++ /dev/null @@ -1,6 +0,0 @@ -# Get terminal size. -function tsize() { - local width=$(tput cols) - local height=$(tput lines) - echo "${width}x${height}" -} diff --git a/module/common/bash/module/Tmp.nix b/module/common/bash/module/Tmp.nix new file mode 100644 index 0000000..dfb8ffd --- /dev/null +++ b/module/common/bash/module/Tmp.nix @@ -0,0 +1,20 @@ +{ ... }: { + text = '' + # CD into host's primary tmp dir. + function tmp() { + local host="''${HOSTNAME}" + local tmp_path + + case "''${host}" in + "desktop"|"home") + tmp_path="/storage/hot/tmp" + ;; + *) + tmp_path="''${HOME}/tmp" + ;; + esac + + cd "''${tmp_path}" + } + ''; +} diff --git a/module/common/bash/module/Tmp.sh b/module/common/bash/module/Tmp.sh deleted file mode 100644 index c857dbd..0000000 --- a/module/common/bash/module/Tmp.sh +++ /dev/null @@ -1,16 +0,0 @@ -# CD into host's primary tmp dir. -function tmp() { - local host="${HOSTNAME}" - local tmp_path - - case "${host}" in - "desktop"|"home") - tmp_path="/storage/hot/tmp" - ;; - *) - tmp_path="${HOME}/tmp" - ;; - esac - - cd "${tmp_path}" -} diff --git a/module/common/bash/module/Tmux.nix b/module/common/bash/module/Tmux.nix new file mode 100644 index 0000000..39aa94f --- /dev/null +++ b/module/common/bash/module/Tmux.nix @@ -0,0 +1,98 @@ +{ ... }: { + text = '' + # Create/attach to named session. + # By default uses current dir name. + # Usage: ta [NAME] + function ta() { + local name="''${1}" + + # Set default name. + # [[ "''${name}" = "" ]] && name="main" + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + + # Create session. + tmux new-session -s "''${name}" -d &> /dev/null + + # Attach to session. + if _is_tmux; then + tmux switch-client -t "''${name}" + else + tmux attach-session -t "''${name}" + fi + } + + # Detach from running session. + function td() { + tmux detach-client + } + + # Detach all other tmux clients. + function tda() { + tmux detach-client -s $(tmux display-message -p '#S') + } + + # List running sessions. + function tl() { + tmux list-sessions + } + + # Assign name to session. Uses current dir name by default. + # Usage: tns [NAME] + function tns() { + local name="''${1}" + + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + + tmux rename-session "''${name}" + } + + # Assign name to window. Uses current dir name by default. + # Usage: tnw [NAME] + function tnw() { + local name="''${1}" + + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + + tmux rename-window "''${name}" + } + + # Kill specified session. + # By default uses current dir name. + # Usage: tk [NAME] + function tk() { + local name="''${1}" + + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + + tmux kill-session -t "''${name}" + } + + # Kill all sessions. + function tka() { + local sessions=$(tmux list-sessions | sed -e 's/:.*//') + + for session in $sessions; do + tmux kill-session -t "$session" + done + } + + # Autocomplete with running sessions once. + function _complete_tmux_session() { + _autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" + } + + # Autocomplete with running sessions. + function _complete_tmux_sessions() { + _autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" + } + + # Autocomplete with current dir name and dirs inside this one. + function _complete_tmux_name() { + _autocomplete_first "''${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//') + } + + complete -F _complete_tmux_session ta + complete -F _complete_tmux_sessions tk + complete -o nosort -F _complete_tmux_name tns tnw + ''; +} diff --git a/module/common/bash/module/Tmux.sh b/module/common/bash/module/Tmux.sh deleted file mode 100644 index 5736e2e..0000000 --- a/module/common/bash/module/Tmux.sh +++ /dev/null @@ -1,94 +0,0 @@ -# Create/attach to named session. -# By default uses current dir name. -# Usage: ta [NAME] -function ta() { - local name="${1}" - - # Set default name. - # [[ "${name}" = "" ]] && name="main" - [[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}") - - # Create session. - tmux new-session -s "${name}" -d &> /dev/null - - # Attach to session. - if _is_tmux; then - tmux switch-client -t "${name}" - else - tmux attach-session -t "${name}" - fi -} - -# Detach from running session. -function td() { - tmux detach-client -} - -# Detach all other tmux clients. -function tda() { - tmux detach-client -s $(tmux display-message -p '#S') -} - -# List running sessions. -function tl() { - tmux list-sessions -} - -# Assign name to session. Uses current dir name by default. -# Usage: tns [NAME] -function tns() { - local name="${1}" - - [[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}") - - tmux rename-session "${name}" -} - -# Assign name to window. Uses current dir name by default. -# Usage: tnw [NAME] -function tnw() { - local name="${1}" - - [[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}") - - tmux rename-window "${name}" -} - -# Kill specified session. -# By default uses current dir name. -# Usage: tk [NAME] -function tk() { - local name="${1}" - - [[ "${name}" = "" ]] && name=$(parse_alnum "${PWD##*/}") - - tmux kill-session -t "${name}" -} - -# Kill all sessions. -function tka() { - local sessions=$(tmux list-sessions | sed -e 's/:.*//') - - for session in $sessions; do - tmux kill-session -t "$session" - done -} - -# Autocomplete with running sessions once. -function _complete_tmux_session() { - _autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" -} - -# Autocomplete with running sessions. -function _complete_tmux_sessions() { - _autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" -} - -# Autocomplete with current dir name and dirs inside this one. -function _complete_tmux_name() { - _autocomplete_first "${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//') -} - -complete -F _complete_tmux_session ta -complete -F _complete_tmux_sessions tk -complete -o nosort -F _complete_tmux_name tns tnw diff --git a/module/common/bash/module/Todo.nix b/module/common/bash/module/Todo.nix new file mode 100644 index 0000000..e2d10e3 --- /dev/null +++ b/module/common/bash/module/Todo.nix @@ -0,0 +1,8 @@ +{ ... }: { + text = '' + # Open `~/.todo.md` file. + function todo() { + vi ~/.todo.md + } + ''; +} diff --git a/module/common/bash/module/Todo.sh b/module/common/bash/module/Todo.sh deleted file mode 100644 index e973693..0000000 --- a/module/common/bash/module/Todo.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Open `~/.todo.md` file. -function todo() { - vi ~/.todo.md -} diff --git a/module/common/bash/module/Transcode.nix b/module/common/bash/module/Transcode.nix new file mode 100644 index 0000000..feb13fb --- /dev/null +++ b/module/common/bash/module/Transcode.nix @@ -0,0 +1,101 @@ +{ ... }: { + text = '' + # Convert between different formats. + # By default tries to convert all files. + # Usage: transcode [FILES] + function transcode() { + local IFS=$'\n' + local format=''${1} + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + # Report no format. + if [[ "''${format}" = "" ]] || [[ "''${format}" =~ "." ]]; then + _error "No format specified." + help transcode + return 2 + fi + + process() { + # Define context names and status. + local from="''${target##*.}" + local to="''${format}" + local output="''${target##*/}" + output="''${output%.*}.''${to}" + + # Skip if file exists. + [[ -f "''${output}" ]] && { _iterate_skip "Already exists."; return 0; } + + # Support multiple inputs. + [[ "''${to}" = "mp3" ]] && from="" + [[ "''${to}" = "flac" ]] && from="" + [[ "''${to}" = "mka" ]] && from="" + [[ "''${to}" = "mkv" ]] && from="" + + # Send convert. + case "''${from}-''${to}" in + "gz-xz"|"tgz-txz") + _transcode_gz-xz "''${target}" "''${output}" + ;; + "xz-gz"|"txz-tgz") + _transcode_xz-gz "''${target}" "''${output}" + ;; + "-mp3") + _transcode_mp3 "''${target}" "''${output}" + ;; + "-flac") + _transcode_flac "''${target}" "''${output}" + ;; + "-mka") + _transcode_mka "''${target}" "''${output}" + ;; + "-mkv") + _transcode_mkv "''${target}" "''${output}" + ;; + *) + _error "Conversion ''${target##*.}-''${to} not supported." + return 1 + ;; + esac + } + + _iterate_targets process ''${targets[@]} + } + + function _transcode_gz-xz() { + [[ -f "''${2}" ]] && return 1 + pv "''${1}" | gzip -d | xz -9e > "''${2}" + } + + function _transcode_xz-gz() { + [[ -f "''${2}" ]] && return 1 + pv "''${1}" | xz -d | gzip -1 > "''${2}" + } + + function _transcode_mp3() { + ffmpeg -n -i "''${1}" -c:a libmp3lame -b:a 320k -f mp3 "''${2}" + } + + function _transcode_flac() { + ffmpeg -n -i "''${1}" -c:a flac -f flac "''${2}" + } + + function _transcode_mka() { + local braudio=$(_ffprobe_ba "''${1}") + [[ ''${braudio} -gt 128 ]] && braudio=128 + + ffmpeg -n -i "''${1}" -ac 2 -c:a libopus -b:a ''${braudio}k -vn "''${2}" + } + + function _transcode_mkv() { + local keyint=$(_ffprobe_keyint "''${1}") + local braudio=$(_ffprobe_ba "''${1}") + local fps=$(_ffprobe_fps "''${1}") + [[ ''${braudio} -gt 128 ]] && braudio=128 + [[ ''${fps} -gt 30 ]] && fps=30 + + # ffmpeg -n -i "''${1}" -c:a libopus -b:a ''${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -preset 8 -pix_fmt yuv420p10le -g ''${keyint} -vf "scale=-2:min'(1080,ih)'" "''${2}" + ffmpeg -n -i "''${1}" -map 0 -map -v -map V -map -t -dn -c:s srt -ac 2 -c:a libopus -b:a ''${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "tune=0" -pix_fmt yuv420p10le -g ''${keyint} -vf "scale=-2:min'(1080,ih)' , fps=''${fps}" "''${2}" + } + ''; +} diff --git a/module/common/bash/module/Transcode.sh b/module/common/bash/module/Transcode.sh deleted file mode 100644 index 36f4971..0000000 --- a/module/common/bash/module/Transcode.sh +++ /dev/null @@ -1,97 +0,0 @@ -# Convert between different formats. -# By default tries to convert all files. -# Usage: transcode [FILES] -function transcode() { - local IFS=$'\n' - local format=${1} - local targets=(${@:2}) - [[ "${targets}" = "" ]] && targets=($(_ls_file)) - - # Report no format. - if [[ "${format}" = "" ]] || [[ "${format}" =~ "." ]]; then - _error "No format specified." - help transcode - return 2 - fi - - process() { - # Define context names and status. - local from="${target##*.}" - local to="${format}" - local output="${target##*/}" - output="${output%.*}.${to}" - - # Skip if file exists. - [[ -f "${output}" ]] && { _iterate_skip "Already exists."; return 0; } - - # Support multiple inputs. - [[ "${to}" = "mp3" ]] && from="" - [[ "${to}" = "flac" ]] && from="" - [[ "${to}" = "mka" ]] && from="" - [[ "${to}" = "mkv" ]] && from="" - - # Send convert. - case "${from}-${to}" in - "gz-xz"|"tgz-txz") - _transcode_gz-xz "${target}" "${output}" - ;; - "xz-gz"|"txz-tgz") - _transcode_xz-gz "${target}" "${output}" - ;; - "-mp3") - _transcode_mp3 "${target}" "${output}" - ;; - "-flac") - _transcode_flac "${target}" "${output}" - ;; - "-mka") - _transcode_mka "${target}" "${output}" - ;; - "-mkv") - _transcode_mkv "${target}" "${output}" - ;; - *) - _error "Conversion ${target##*.}-${to} not supported." - return 1 - ;; - esac - } - - _iterate_targets process ${targets[@]} -} - -function _transcode_gz-xz() { - [[ -f "${2}" ]] && return 1 - pv "${1}" | gzip -d | xz -9e > "${2}" -} - -function _transcode_xz-gz() { - [[ -f "${2}" ]] && return 1 - pv "${1}" | xz -d | gzip -1 > "${2}" -} - -function _transcode_mp3() { - ffmpeg -n -i "${1}" -c:a libmp3lame -b:a 320k -f mp3 "${2}" -} - -function _transcode_flac() { - ffmpeg -n -i "${1}" -c:a flac -f flac "${2}" -} - -function _transcode_mka() { - local braudio=$(_ffprobe_ba "${1}") - [[ ${braudio} -gt 128 ]] && braudio=128 - - ffmpeg -n -i "${1}" -ac 2 -c:a libopus -b:a ${braudio}k -vn "${2}" -} - -function _transcode_mkv() { - local keyint=$(_ffprobe_keyint "${1}") - local braudio=$(_ffprobe_ba "${1}") - local fps=$(_ffprobe_fps "${1}") - [[ ${braudio} -gt 128 ]] && braudio=128 - [[ ${fps} -gt 30 ]] && fps=30 - - # ffmpeg -n -i "${1}" -c:a libopus -b:a ${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -preset 8 -pix_fmt yuv420p10le -g ${keyint} -vf "scale=-2:min'(1080,ih)'" "${2}" - ffmpeg -n -i "${1}" -map 0 -map -v -map V -map -t -dn -c:s srt -ac 2 -c:a libopus -b:a ${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "tune=0" -pix_fmt yuv420p10le -g ${keyint} -vf "scale=-2:min'(1080,ih)' , fps=${fps}" "${2}" -} diff --git a/module/common/bash/module/Try.nix b/module/common/bash/module/Try.nix new file mode 100644 index 0000000..33ceb0d --- /dev/null +++ b/module/common/bash/module/Try.nix @@ -0,0 +1,25 @@ +{ ... }: { + text = '' + # Retry command every 2 sec until it completes successfully. + # Usage: try + function try() { + if [[ "''${*}" = "" ]]; then + help try + return 2 + fi + + local result=-1 + + while [ "$result" != 0 ]; do + ''${*} + result=$? + if [ "$result" != 0 ]; then + sleep 2 + fi + done + } + + # autocomplete. + complete -F _autocomplete_nested try + ''; +} diff --git a/module/common/bash/module/Try.sh b/module/common/bash/module/Try.sh deleted file mode 100644 index a8714e3..0000000 --- a/module/common/bash/module/Try.sh +++ /dev/null @@ -1,21 +0,0 @@ -# Retry command every 2 sec until it completes successfully. -# Usage: try -function try() { - if [[ "${*}" = "" ]]; then - help try - return 2 - fi - - local result=-1 - - while [ "$result" != 0 ]; do - ${*} - result=$? - if [ "$result" != 0 ]; then - sleep 2 - fi - done -} - -# autocomplete. -complete -F _autocomplete_nested try diff --git a/module/common/bash/module/Util.nix b/module/common/bash/module/Util.nix new file mode 100644 index 0000000..47a0f9f --- /dev/null +++ b/module/common/bash/module/Util.nix @@ -0,0 +1,160 @@ +{ ... }: { + text = '' + # Get the number of avaialble cores (threads). + function _core_count() { + cat /proc/cpuinfo | grep ^processor | wc -l + } + + # Get the number of available memory (in mebibytes). + function _mem_free() { + free -m | sed -n -e '2p' | awk '{print $7}' + } + + # Function-wrapper to iterate with specified function with provided files. + # By default Iterates on all non-hidden files and directories. + # List of variables available to FUNCTION: target - current file, count - current item index, total - sum of targets, failed - count of previously failed items, skipped - count of skipped files, status - status line (not recommended to use). + # Usage: _iterate_targets [FILES] + function _iterate_targets() { + local IFS=$'\n' + local foo="''${1}" + local targets=("''${@:2}") + local total=''${#targets[@]} + local count=0 + local failed=0 + local skipped=0 + local code=0 + + # set dafult value to target all supported archives. + if [[ "''${targets}" = "" ]]; then + _error "No targets provided." + return 1 + fi + + # iterate each target. + for target in "''${targets[@]}"; do + # increment counter. + ((count++)) + + # status info. + local status="[''${count}/''${total}] ''${target}" + _info "''${status}" + + # Call function. + ''${foo} "''${target}" + + # Show error. + if [[ ''${?} != 0 ]]; then + ((failed++)) + _error "''${status}: Failed." + fi + + # Add newline if not the last one. + [[ "''${count}" = "''${total}" ]] || _info + done + + # Show skipped. + if [[ ''${skipped} != 0 ]]; then + _warn + _warn "''${color_byellow}Skipped: ''${skipped}.''${color_default}" + fi + + # Show error. + if [[ ''${failed} != 0 ]]; then + [[ "''${skipped}" = 0 ]] && _error + _error "''${color_bred}Failed: ''${failed}.''${color_default}" + false + fi + } + + # Skip current iteration. + # Usage: _iterate_skip [MESSAGE] + function _iterate_skip() { + ((skipped++)) + + [[ "''${*}" != "" ]] && _warn "''${color_byellow}''${*}''${color_default}" + } + + # Report an error. + # Always returns code 1. + # Usage: _error + function _error() { + >&2 echo -e "''${color_bred}''${*}''${color_default}" + return 1 + } + + # Report a warning. + # Usage: _warn + function _warn() { + >&2 echo -e "''${color_byellow}''${*}''${color_default}" + } + + # Report a debug. + # Usage: _debug + function _debug() { + >&2 echo -e "''${color_bwhite}''${*}''${color_default}" + } + + # Report an info. + # Usage: _info + function _info() { + >&2 echo -e "''${color_bwhite}''${*}''${color_default}" + } + + # Check if array contains an element (strict). + # Usage: _contains + function _contains() { + local IFS=$'\n' + local target="''${1}" + local array="''${@:2}" + + if [[ "''${target}" = "" ]] || [[ "''${array}" = "" ]]; then + help _contains + return 2 + fi + + for item in ''${array[@]}; do + [[ "''${item}" = "''${target}" ]] && return 0 + done + + return 1 + } + + # Check if inside Tmux. + function _is_tmux() { + [[ "''${TERM_PROGRAM}" = "tmux" ]] + } + + # Check if root. + function _is_root() { + [[ "''${UID}" = 0 ]] + } + + # Ring a bell. + function _bell() { + echo -e '\a' + } + + # Get users. + function _get_users() { + local users=("voronind" "dasha") + echo ''${users[@]} + } + + # Force the command to be called twice within the specified period in seconds. Used primarily in important keyboard shortcuts like poweroff. + # Usage: _twice + function _twice() { + local IFS=$'\n' + local file="/tmp/.twice" + local period=''${1} + local command="''${@:2}" + + if [[ "$(cat ''${file} 2> /dev/null)" = "''${command}" ]]; then + ''${command} + return 0 + fi + echo "''${command}" > "''${file}" + sleep ''${period} + rm "''${file}" 2> /dev/null + } + ''; +} diff --git a/module/common/bash/module/Util.sh b/module/common/bash/module/Util.sh deleted file mode 100644 index 492c97a..0000000 --- a/module/common/bash/module/Util.sh +++ /dev/null @@ -1,156 +0,0 @@ -# Get the number of avaialble cores (threads). -function _core_count() { - cat /proc/cpuinfo | grep ^processor | wc -l -} - -# Get the number of available memory (in mebibytes). -function _mem_free() { - free -m | sed -n -e '2p' | awk '{print $7}' -} - -# Function-wrapper to iterate with specified function with provided files. -# By default Iterates on all non-hidden files and directories. -# List of variables available to FUNCTION: target - current file, count - current item index, total - sum of targets, failed - count of previously failed items, skipped - count of skipped files, status - status line (not recommended to use). -# Usage: _iterate_targets [FILES] -function _iterate_targets() { - local IFS=$'\n' - local foo="${1}" - local targets=("${@:2}") - local total=${#targets[@]} - local count=0 - local failed=0 - local skipped=0 - local code=0 - - # set dafult value to target all supported archives. - if [[ "${targets}" = "" ]]; then - _error "No targets provided." - return 1 - fi - - # iterate each target. - for target in "${targets[@]}"; do - # increment counter. - ((count++)) - - # status info. - local status="[${count}/${total}] ${target}" - _info "${status}" - - # Call function. - ${foo} "${target}" - - # Show error. - if [[ ${?} != 0 ]]; then - ((failed++)) - _error "${status}: Failed." - fi - - # Add newline if not the last one. - [[ "${count}" = "${total}" ]] || _info - done - - # Show skipped. - if [[ ${skipped} != 0 ]]; then - _warn - _warn "${color_byellow}Skipped: ${skipped}.${color_default}" - fi - - # Show error. - if [[ ${failed} != 0 ]]; then - [[ "${skipped}" = 0 ]] && _error - _error "${color_bred}Failed: ${failed}.${color_default}" - false - fi -} - -# Skip current iteration. -# Usage: _iterate_skip [MESSAGE] -function _iterate_skip() { - ((skipped++)) - - [[ "${*}" != "" ]] && _warn "${color_byellow}${*}${color_default}" -} - -# Report an error. -# Always returns code 1. -# Usage: _error -function _error() { - >&2 echo -e "${color_bred}${*}${color_default}" - return 1 -} - -# Report a warning. -# Usage: _warn -function _warn() { - >&2 echo -e "${color_byellow}${*}${color_default}" -} - -# Report a debug. -# Usage: _debug -function _debug() { - >&2 echo -e "${color_bwhite}${*}${color_default}" -} - -# Report an info. -# Usage: _info -function _info() { - >&2 echo -e "${color_bwhite}${*}${color_default}" -} - -# Check if array contains an element (strict). -# Usage: _contains -function _contains() { - local IFS=$'\n' - local target="${1}" - local array="${@:2}" - - if [[ "${target}" = "" ]] || [[ "${array}" = "" ]]; then - help _contains - return 2 - fi - - for item in ${array[@]}; do - [[ "${item}" = "${target}" ]] && return 0 - done - - return 1 -} - -# Check if inside Tmux. -function _is_tmux() { - [[ "${TERM_PROGRAM}" = "tmux" ]] -} - -# Check if root. -function _is_root() { - [[ "${UID}" = 0 ]] -} - -# Ring a bell. -function _bell() { - echo -e '\a' -} - -# Get users. -function _get_users() { - local users=("voronind" "dasha") - echo ${users[@]} -} - -# Force the command to be called twice within the specified period in seconds. Used primarily in important keyboard shortcuts like poweroff. -# Usage: _twice -function _twice() { - local IFS=$'\n' - local file="/tmp/.twice" - local period=${1} - local command="${@:2}" - - if [[ "$(cat ${file} 2> /dev/null)" = "${command}" ]]; then - ${command} - return 0 - fi - echo "${command}" > "${file}" - sleep ${period} - rm "${file}" 2> /dev/null -} diff --git a/module/common/bash/module/Vdl.nix b/module/common/bash/module/Vdl.nix new file mode 100644 index 0000000..d917ac1 --- /dev/null +++ b/module/common/bash/module/Vdl.nix @@ -0,0 +1,43 @@ +{ ... }: { + text = '' + # Download video from URL. When no `[LINK]` specified, it tries to update previously downloaded link. + # Usage: vdl [LINK] + function vdl() { + # Check that ffmpeg and ffprobe are available. + if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then + _error "ffmpeg and ffprobe are required." + return 1 + fi + + local target="''${@}" # What to download/update. + + # If no [LINK] provided, try to read from `Src.txt`. + [[ "''${target}" = "" ]] && target="$(cat Src.txt)" + + # If could not get [LINK] eventually, show an error and exit. + if [[ "''${target}" = "" ]]; then + _error "Could not determine [LINK] to download." + help vdl + return 2 + fi + + # Save [LINK] for later use. + [[ -f "Src.txt" ]] || echo "''${target}" > Src.txt + + # Download [LINK] content. + yt-dlp -f 'bestvideo[height<=?1081]+bestaudio/best' --download-archive Index.txt --embed-thumbnail --embed-subs --write-auto-subs --embed-metadata --merge-output-format mkv -cio '%(playlist_index)000006d_%(id)s.%(ext)s' ''${target} # || _vdl_retry + } + + # Temporary fix for vk downloads. + # Usage: vdl_vk + function vdl_vk() { + vdl --format mp4 "''${@}" + } + + # Download all videos from file with links. + # Usage: vdl_file + function vdl_file() { + vdl -a "''${@}" + } + ''; +} diff --git a/module/common/bash/module/Vdl.sh b/module/common/bash/module/Vdl.sh deleted file mode 100644 index 9432089..0000000 --- a/module/common/bash/module/Vdl.sh +++ /dev/null @@ -1,39 +0,0 @@ -# Download video from URL. When no `[LINK]` specified, it tries to update previously downloaded link. -# Usage: vdl [LINK] -function vdl() { - # Check that ffmpeg and ffprobe are available. - if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then - _error "ffmpeg and ffprobe are required." - return 1 - fi - - local target="${@}" # What to download/update. - - # If no [LINK] provided, try to read from `Src.txt`. - [[ "${target}" = "" ]] && target="$(cat Src.txt)" - - # If could not get [LINK] eventually, show an error and exit. - if [[ "${target}" = "" ]]; then - _error "Could not determine [LINK] to download." - help vdl - return 2 - fi - - # Save [LINK] for later use. - [[ -f "Src.txt" ]] || echo "${target}" > Src.txt - - # Download [LINK] content. - yt-dlp -f 'bestvideo[height<=?1081]+bestaudio/best' --download-archive Index.txt --embed-thumbnail --embed-subs --write-auto-subs --embed-metadata --merge-output-format mkv -cio '%(playlist_index)000006d_%(id)s.%(ext)s' ${target} # || _vdl_retry -} - -# Temporary fix for vk downloads. -# Usage: vdl_vk -function vdl_vk() { - vdl --format mp4 "${@}" -} - -# Download all videos from file with links. -# Usage: vdl_file -function vdl_file() { - vdl -a "${@}" -} diff --git a/module/common/bash/module/Vi.nix b/module/common/bash/module/Vi.nix new file mode 100644 index 0000000..d813bfe --- /dev/null +++ b/module/common/bash/module/Vi.nix @@ -0,0 +1,8 @@ +{ ... }: { + text = '' + # Neovim shortcut. + function v() { + nvim -- "''${@}" + } + ''; +} diff --git a/module/common/bash/module/Vi.sh b/module/common/bash/module/Vi.sh deleted file mode 100644 index a7e7d84..0000000 --- a/module/common/bash/module/Vi.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Neovim shortcut. -function v() { - nvim -- "${@}" -} diff --git a/module/common/bash/module/Vrr.nix b/module/common/bash/module/Vrr.nix new file mode 100644 index 0000000..4fd3ef9 --- /dev/null +++ b/module/common/bash/module/Vrr.nix @@ -0,0 +1,13 @@ +{ ... }: { + text = '' + # Enable VRR. + function vrron() { + swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync on' + } + + # Disable VRR. + function vrroff() { + swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync off' + } + ''; +} diff --git a/module/common/bash/module/Vrr.sh b/module/common/bash/module/Vrr.sh deleted file mode 100644 index d60eb8d..0000000 --- a/module/common/bash/module/Vrr.sh +++ /dev/null @@ -1,9 +0,0 @@ -# Enable VRR. -function vrron() { - swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync on' -} - -# Disable VRR. -function vrroff() { - swaymsg 'output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" adaptive_sync off' -} diff --git a/module/common/bash/module/Watch.nix b/module/common/bash/module/Watch.nix new file mode 100644 index 0000000..167f990 --- /dev/null +++ b/module/common/bash/module/Watch.nix @@ -0,0 +1,28 @@ +{ ... }: { + text = '' + # Watch command output with 2 seconds interval. + # Usage: w + function w() { + if [[ "''${*}" = "" ]]; then + help w + return 2 + fi + + watch -n 2 "''${@}" + } + + # Watch command output with minimal interval. + # Usage: ww + function ww() { + if [[ "''${*}" = "" ]]; then + help ww + return 2 + fi + + watch -n 0 "''${@}" + } + + # Autocomplete. + complete -F _autocomplete_nested w ww + ''; +} diff --git a/module/common/bash/module/Watch.sh b/module/common/bash/module/Watch.sh deleted file mode 100644 index 1734791..0000000 --- a/module/common/bash/module/Watch.sh +++ /dev/null @@ -1,24 +0,0 @@ -# Watch command output with 2 seconds interval. -# Usage: w -function w() { - if [[ "${*}" = "" ]]; then - help w - return 2 - fi - - watch -n 2 "${@}" -} - -# Watch command output with minimal interval. -# Usage: ww -function ww() { - if [[ "${*}" = "" ]]; then - help ww - return 2 - fi - - watch -n 0 "${@}" -} - -# Autocomplete. -complete -F _autocomplete_nested w ww diff --git a/module/common/firefox/Config.js b/module/common/firefox/Config.js deleted file mode 100644 index 9fe2f7e..0000000 --- a/module/common/firefox/Config.js +++ /dev/null @@ -1,35 +0,0 @@ -// Bookmarks. -lockPref("browser.microsummary.enabled", true); -lockPref("browser.places.importBookmarksHTML", true); -lockPref("browser.toolbars.bookmarks.visibility", "never"); - -// Fonts. -pref("browser.display.use_document_fonts", 0); -lockPref("font.minimum-size.x-cyrillic", 12); -lockPref("font.minimum-size.x-unicode", 12); -lockPref("font.minimum-size.x-western", 12); -lockPref("font.name.monospace.x-cyrillic", "Terminess Nerd Font Mono"); -lockPref("font.name.monospace.x-unicode", "Terminess Nerd Font Mono"); -lockPref("font.name.monospace.x-western", "Terminess Nerd Font Mono"); -lockPref("font.name.sans-serif.x-cyrillic", "SF Pro Text"); -lockPref("font.name.sans-serif.x-unicode", "SF Pro Text"); -lockPref("font.name.sans-serif.x-western", "SF Pro Text"); -lockPref("font.name.serif.x-cyrillic", "SF Pro Text"); -lockPref("font.name.serif.x-unicode", "SF Pro Text"); -lockPref("font.name.serif.x-western", "SF Pro Text"); - -// Animations. -lockPref("browser.fullscreen.animateUp", 0); -lockPref("browser.fullscreen.autohide", true); - -// Homepage. -lockPref("browser.newtabpage.enabled", false); -lockPref("browser.startup.homepage", "https://home.voronind.com/"); -lockPref("browser.startup.page", 3); - -// Passwords. -lockPref("signon.prefillForms", false); -lockPref("signon.rememberSignons", false); - -// Formats. -lockPref("image.jxl.enabled", true); diff --git a/module/common/firefox/Init.nix b/module/common/firefox/Init.nix new file mode 100644 index 0000000..38b8e00 --- /dev/null +++ b/module/common/firefox/Init.nix @@ -0,0 +1,39 @@ +{ util, ... }: { + config = util.trimTabs '' + // Bookmarks. + lockPref("browser.microsummary.enabled", true); + lockPref("browser.places.importBookmarksHTML", true); + lockPref("browser.toolbars.bookmarks.visibility", "never"); + + // Fonts. + pref("browser.display.use_document_fonts", 0); + lockPref("font.minimum-size.x-cyrillic", 12); + lockPref("font.minimum-size.x-unicode", 12); + lockPref("font.minimum-size.x-western", 12); + lockPref("font.name.monospace.x-cyrillic", "Terminess Nerd Font Mono"); + lockPref("font.name.monospace.x-unicode", "Terminess Nerd Font Mono"); + lockPref("font.name.monospace.x-western", "Terminess Nerd Font Mono"); + lockPref("font.name.sans-serif.x-cyrillic", "SF Pro Text"); + lockPref("font.name.sans-serif.x-unicode", "SF Pro Text"); + lockPref("font.name.sans-serif.x-western", "SF Pro Text"); + lockPref("font.name.serif.x-cyrillic", "SF Pro Text"); + lockPref("font.name.serif.x-unicode", "SF Pro Text"); + lockPref("font.name.serif.x-western", "SF Pro Text"); + + // Animations. + lockPref("browser.fullscreen.animateUp", 0); + lockPref("browser.fullscreen.autohide", true); + + // Homepage. + lockPref("browser.newtabpage.enabled", false); + lockPref("browser.startup.homepage", "https://home.voronind.com/"); + lockPref("browser.startup.page", 3); + + // Passwords. + lockPref("signon.prefillForms", false); + lockPref("signon.rememberSignons", false); + + // Formats. + lockPref("image.jxl.enabled", true); + ''; +} diff --git a/module/common/nvim/Init.nix b/module/common/nvim/Init.nix index 240c0bb..c84f9ce 100644 --- a/module/common/nvim/Init.nix +++ b/module/common/nvim/Init.nix @@ -1,15 +1,17 @@ -{ inputs, ... }: let - nvimRc = { cfgPath, runtimes, cfgs }: let +{ inputs, pkgs, util, key, ... } @args: let + nvimRc = { runtimes, cfgs }: let runtimeRc = builtins.foldl' (acc: r: acc + "set runtimepath+=${r}\n" ) "" runtimes; - cfgRc = builtins.foldl' (acc: c: - acc + "lua dofile(\"${cfgPath}/${c}\")\n" - ) "" cfgs; + + config = pkgs.writeText "nvimRc" (builtins.foldl' (acc: cfg: + acc + (import cfg args).text + ) "" cfgs); + + cfgRc = "lua dofile(\"${config}\")"; in runtimeRc + cfgRc; in { - customRc = nvimRc { - cfgPath = ./src; + config = util.trimTabs (nvimRc { runtimes = [ "~/.cache/nvim" "~/.cache/nvim/treesitter" @@ -35,49 +37,47 @@ in { "${inputs.nvimWhichKey}" ]; cfgs = [ - "key/Rekey.lua" - "key/Leader.lua" - "config/Autoread.lua" - "config/Etc.lua" - "config/Search.lua" - "config/Tab.lua" - "plugin/Filetree.lua" - "plugin/Gruvbox.lua" - "plugin/Bufferline.lua" - "plugin/Autoclose.lua" - "plugin/Gitsigns.lua" - "plugin/Trouble.lua" - "plugin/Tokyonight.lua" - "plugin/Closebuffers.lua" - "plugin/Telescope.lua" - "plugin/Todo.lua" - "plugin/Indent.lua" - "plugin/Align.lua" - "plugin/Treesitter.lua" - "plugin/Fold.lua" - "plugin/Ollama.lua" - "plugin/Colorizer.lua" - "plugin/lsp/Haskell.lua" - "plugin/lsp/Rust.lua" - "plugin/lsp/Tex.lua" - "plugin/lsp/Nix.lua" - "key/Autocomplete.lua" - "key/Buffer.lua" - "key/Colorscheme.lua" - "key/Comment.lua" - "key/Common.lua" - "key/Filetree.lua" - "key/Gitsigns.lua" - "key/Lsp.lua" - "key/Navigation.lua" - "key/Ollama.lua" - "key/Sort.lua" - "key/Telescope.lua" - "key/Terminal.lua" - "key/Todo.lua" - "key/Trouble.lua" - "key/Update.lua" - "key/Whichkey.lua" + ./module/key/Rekey.nix + ./module/key/Leader.nix + ./module/config/Autoread.nix + ./module/config/Etc.nix + ./module/config/Search.nix + ./module/config/Tab.nix + ./module/plugin/Filetree.nix + ./module/plugin/Gruvbox.nix + ./module/plugin/Bufferline.nix + ./module/plugin/Autoclose.nix + ./module/plugin/Gitsigns.nix + ./module/plugin/Trouble.nix + ./module/plugin/Tokyonight.nix + ./module/plugin/Closebuffers.nix + ./module/plugin/Telescope.nix + ./module/plugin/Todo.nix + ./module/plugin/Indent.nix + ./module/plugin/Align.nix + ./module/plugin/Treesitter.nix + ./module/plugin/Fold.nix + ./module/plugin/Ollama.nix + ./module/plugin/Colorizer.nix + ./module/plugin/lsp/Haskell.nix + ./module/plugin/lsp/Rust.nix + ./module/plugin/lsp/Tex.nix + ./module/plugin/lsp/Nix.nix + ./module/key/Autocomplete.nix + ./module/key/Buffer.nix + ./module/key/Colorscheme.nix + ./module/key/Comment.nix + ./module/key/Common.nix + ./module/key/Filetree.nix + ./module/key/Gitsigns.nix + ./module/key/Navigation.nix + ./module/key/Ollama.nix + ./module/key/Sort.nix + ./module/key/Telescope.nix + ./module/key/Terminal.nix + ./module/key/Todo.nix + ./module/key/Trouble.nix + ./module/key/Whichkey.nix ]; - }; + }); } diff --git a/module/common/nvim/module/config/Autoread.nix b/module/common/nvim/module/config/Autoread.nix new file mode 100644 index 0000000..d62589e --- /dev/null +++ b/module/common/nvim/module/config/Autoread.nix @@ -0,0 +1,9 @@ +{ ... }: { + text = '' + vim.o.autoread = true + vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "CursorHoldI", "FocusGained" }, { + command = "if mode() != 'c' | checktime | endif", + pattern = { "*" }, + }) + ''; +} diff --git a/module/common/nvim/module/config/Etc.nix b/module/common/nvim/module/config/Etc.nix new file mode 100644 index 0000000..7e8c551 --- /dev/null +++ b/module/common/nvim/module/config/Etc.nix @@ -0,0 +1,31 @@ +{ setting, ... }: { + text = '' + -- TODO: Add comments and separate files. + vim.opt.clipboard = "unnamedplus" + -- vim.opt.completeopt = "menuone,noselect" + vim.opt.cursorline = false + vim.opt.fixeol = false + vim.opt.number = true + vim.opt.splitbelow = true + vim.opt.splitright = true + vim.opt.termguicolors = true + vim.opt.ttyfast = true + vim.opt.wildmode = "longest,list" + + -- Disable continuing comments on newline. + vim.cmd("autocmd BufEnter * set fo-=c fo-=r fo-=o") + + -- Disable mouse. + vim.cmd("set mouse=") + + -- Disable signs for diagnostics. + vim.diagnostic.config({ signs = false }) + + -- Display invisible characters. + -- vim.cmd("set list listchars=tab:>\\ ,trail:-,eol:,lead:.") + vim.cmd("set list listchars=tab:>\\ ,trail:-,lead:.") + + -- Relative line numbers. + vim.wo.relativenumber = ${setting.nvim.editor.relativenumber} + ''; +} diff --git a/module/common/nvim/module/config/Search.nix b/module/common/nvim/module/config/Search.nix new file mode 100644 index 0000000..5731e34 --- /dev/null +++ b/module/common/nvim/module/config/Search.nix @@ -0,0 +1,9 @@ +{ ... }: { + text = '' + vim.opt.hlsearch = true + vim.opt.ignorecase = true + vim.opt.incsearch = true + vim.opt.showmatch = true + vim.opt.smartcase = true + ''; +} diff --git a/module/common/nvim/module/config/Tab.nix b/module/common/nvim/module/config/Tab.nix new file mode 100644 index 0000000..8c3b82a --- /dev/null +++ b/module/common/nvim/module/config/Tab.nix @@ -0,0 +1,13 @@ +{ setting, ... }: { + text = '' + vim.opt.autoindent = true + vim.opt.expandtab = false + -- vim.opt.smartindent = true + vim.opt.shiftwidth = ${setting.nvim.editor.indent.default} + vim.opt.softtabstop = ${setting.nvim.editor.indent.default} + vim.opt.tabstop = ${setting.nvim.editor.indent.default} + + -- Disable Markdown forced formatting. + vim.g.markdown_recommended_style = 0 + ''; +} diff --git a/module/common/nvim/module/key/Autocomplete.nix b/module/common/nvim/module/key/Autocomplete.nix new file mode 100644 index 0000000..cc88fa2 --- /dev/null +++ b/module/common/nvim/module/key/Autocomplete.nix @@ -0,0 +1,9 @@ +{ key, ... }: { + text = '' + -- Autocomplete. + rekey_input("", "") + + -- LSP autocomplete. + rekey_normal("", "lua vim.lsp.buf.code_action()") + ''; +} diff --git a/module/common/nvim/module/key/Buffer.nix b/module/common/nvim/module/key/Buffer.nix new file mode 100644 index 0000000..8d2ae51 --- /dev/null +++ b/module/common/nvim/module/key/Buffer.nix @@ -0,0 +1,16 @@ +{ key, ... }: { + text = '' + -- New empty buffer. + remap_normal("${key.nvim.buffer.new}", "enew") + + -- Close buffer. + function _buf_close() + pcall(vim.cmd, "w") + vim.cmd[[bp|sp|bn|bd!]] + end + rekey_normal("${key.action.close}", "lua _buf_close()") + + -- Close all hidden buffers. + rekey_normal("${key.action.kill}", "BDelete hidden") + ''; +} diff --git a/module/common/nvim/module/key/Colorscheme.nix b/module/common/nvim/module/key/Colorscheme.nix new file mode 100644 index 0000000..747e867 --- /dev/null +++ b/module/common/nvim/module/key/Colorscheme.nix @@ -0,0 +1,26 @@ +{ key, ... }: { + text = '' + function toggle_contrast() + if vim.g.gruvbox_material_background == "light" then + vim.g.gruvbox_material_background = "medium" + elseif vim.g.gruvbox_material_background == "medium" then + vim.g.gruvbox_material_background = "hard" + elseif vim.g.gruvbox_material_background == "hard" then + vim.g.gruvbox_material_background = "light" + end + vim.cmd("colorscheme gruvbox-material") + end + + function toggle_light() + if vim.o.background == "light" then + vim.o.background = "dark" + elseif vim.o.background == "dark" then + vim.o.background = "light" + end + -- require("lualine").setup() + end + + rekey_normal("${key.nvim.colorscheme.toggle.contrast}", "lua toggle_contrast()") + rekey_normal("${key.nvim.colorscheme.toggle.light}", "lua toggle_light()") + ''; +} diff --git a/module/common/nvim/module/key/Comment.nix b/module/common/nvim/module/key/Comment.nix new file mode 100644 index 0000000..3666b98 --- /dev/null +++ b/module/common/nvim/module/key/Comment.nix @@ -0,0 +1,9 @@ +{ key, ... }: { + text = '' + -- Toggle comment for the selected line. + vim.keymap.set("n", "${key.nvim.text.comment}", require("SingleComment").SingleComment, { expr = true }) + + -- Toggle comments for multiple lines. + vim.keymap.set("v", "${key.nvim.text.comment}", require("SingleComment").Comment, {}) + ''; +} diff --git a/module/common/nvim/module/key/Common.nix b/module/common/nvim/module/key/Common.nix new file mode 100644 index 0000000..b1effaf --- /dev/null +++ b/module/common/nvim/module/key/Common.nix @@ -0,0 +1,41 @@ +{ key, ... }: { + text = '' + -- Write all we can and exit. Created this to drop non-writable stuff when piping to nvim. + function bye() + pcall(vim.cmd, "wa") + vim.cmd[[qa!]] + end + + function toggle_tab_width() + if vim.bo.shiftwidth == 2 then + vim.bo.shiftwidth = 4 + vim.bo.tabstop = 4 + vim.bo.softtabstop = 4 + elseif vim.bo.shiftwidth == 4 then + vim.bo.shiftwidth = 8 + vim.bo.tabstop = 8 + vim.bo.softtabstop = 8 + elseif vim.bo.shiftwidth == 8 then + vim.bo.shiftwidth = 2 + vim.bo.tabstop = 2 + vim.bo.softtabstop = 2 + end + end + + rekey_normal("${key.nvim.editor.indent.size}", "lua toggle_tab_width()") + + -- Repeat previous command. + rekey_normal("${key.action.repeat}", "@:") + rekey_visual("${key.action.repeat}", "@:") + + -- Save everything. + rekey_normal("${key.action.wait}${key.action.wait}", "wa") + + -- Save all we can and leave. + rekey_normal("${key.action.wait}", "lua bye()") + + -- Remap ; to :. + rekey_normal(";", ":") + rekey_visual(";", ":") + ''; +} diff --git a/module/common/nvim/module/key/Filetree.nix b/module/common/nvim/module/key/Filetree.nix new file mode 100644 index 0000000..21be781 --- /dev/null +++ b/module/common/nvim/module/key/Filetree.nix @@ -0,0 +1,6 @@ +{ key, ... }: { + text = '' + -- Toggle file tree. + rekey_normal("${key.nvim.window.filetree}", "NvimTreeToggle") + ''; +} diff --git a/module/common/nvim/module/key/Gitsigns.nix b/module/common/nvim/module/key/Gitsigns.nix new file mode 100644 index 0000000..e9fae8a --- /dev/null +++ b/module/common/nvim/module/key/Gitsigns.nix @@ -0,0 +1,6 @@ +{ key, ... }: { + text = '' + -- Toggle Git inspection mode. + rekey_normal("${key.nvim.editor.git.inspect}", "Gitsigns toggle_current_line_blameGitsigns toggle_word_diffGitsigns toggle_linehl") + ''; +} diff --git a/module/common/nvim/module/key/Leader.nix b/module/common/nvim/module/key/Leader.nix new file mode 100644 index 0000000..64ec364 --- /dev/null +++ b/module/common/nvim/module/key/Leader.nix @@ -0,0 +1,11 @@ +{ key, ... }: { + text = '' + leader = "${key.meta.app.nvim}" + + vim.g.mapleader = leader + vim.g.maplocalleader = leader + + -- Disable key press timeout. + vim.cmd("set notimeout nottimeout") + ''; +} diff --git a/module/common/nvim/module/key/Navigation.nix b/module/common/nvim/module/key/Navigation.nix new file mode 100644 index 0000000..f23afd6 --- /dev/null +++ b/module/common/nvim/module/key/Navigation.nix @@ -0,0 +1,33 @@ +{ key, setting, ... }: { + text = '' + -- Switch windows. + rekey_normal("${key.navigation.go.left}", "h") + rekey_normal("${key.navigation.go.right}", "l") + rekey_normal("${key.navigation.go.down}", "j") + rekey_normal("${key.navigation.go.up}", "k") + + -- Switch buffers. + rekey_normal("${key.navigation.move.next}", "BufferLineMoveNext") + rekey_normal("${key.navigation.move.prev}", "BufferLineMovePrev") + rekey_normal("${key.navigation.go.next}", "BufferLineCycleNext") + rekey_normal("${key.navigation.go.prev}", "BufferLineCyclePrev") + + -- Splits. + rekey_normal("${key.action.split.vertical}", "vsplit") + rekey_normal("${key.action.split.horizontal}", "split") + rekey_normal("${key.action.resize.equalize}", "=") -- Equalize split sizes. + rekey_normal("${key.action.hide}", "q") -- Close split. + + -- Resize splits. + rekey_normal("${key.action.resize.left}", "${setting.tmux.resize.step.horizontal}<") + rekey_normal("${key.action.resize.right}", "${setting.tmux.resize.step.horizontal}>") + rekey_normal("${key.action.resize.down}", "${setting.tmux.resize.step.vertical}+") + rekey_normal("${key.action.resize.up}", "${setting.tmux.resize.step.vertical}-") + + -- Move splits. + rekey_normal("${key.navigation.move.left}", "A") + rekey_normal("${key.navigation.move.right}", "D") + rekey_normal("${key.navigation.move.down}", "S") + rekey_normal("${key.navigation.move.up}", "W") + ''; +} diff --git a/module/common/nvim/module/key/Ollama.nix b/module/common/nvim/module/key/Ollama.nix new file mode 100644 index 0000000..a3374e7 --- /dev/null +++ b/module/common/nvim/module/key/Ollama.nix @@ -0,0 +1,8 @@ +{ key, ... }: let + prompt = key.nvim.text.prompt; +in { + text = '' + rekey_normal("${prompt}", ":lua require('ollama').prompt()") + rekey_visual("${prompt}", ":lua require('ollama').prompt()") + ''; +} diff --git a/module/common/nvim/module/key/Rekey.nix b/module/common/nvim/module/key/Rekey.nix new file mode 100644 index 0000000..00e052a --- /dev/null +++ b/module/common/nvim/module/key/Rekey.nix @@ -0,0 +1,53 @@ +{ ... }: { + text = '' + -- Base rekey function. + local function rekey(t, key, command) + vim.api.nvim_set_keymap(t, key, command, { noremap = true }) + end + + -- Base remap function. + local function remap(t, key, command) + vim.api.nvim_set_keymap(t, key, command, { noremap = false }) + end + + -- Rekey in normal mode. + function rekey_normal(key, command) + rekey("n", key, command) + end + + -- Rekey in input mode. + function rekey_input(key, command) + rekey("i", key, command) + end + + -- Rekey in visual mode. + function rekey_visual(key, command) + rekey("v", key, command) + end + + -- Rekey in terminal mode. + function rekey_terminal(key, command) + rekey("t", key, command) + end + + -- Remap in normal mode. + function remap_normal(key, command) + remap("n", key, command) + end + + -- Remap in input mode. + function remap_input(key, command) + remap("i", key, command) + end + + -- Remap in visual mode. + function remap_visual(key, command) + remap("v", key, command) + end + + -- Remap in terminal mode. + function remap_terminal(key, command) + remap("t", key, command) + end + ''; +} diff --git a/module/common/nvim/module/key/Sort.nix b/module/common/nvim/module/key/Sort.nix new file mode 100644 index 0000000..e2bc7dc --- /dev/null +++ b/module/common/nvim/module/key/Sort.nix @@ -0,0 +1,6 @@ +{ key, ... }: { + text = '' + -- Sort visual selection alphabetically. + rekey_visual("${key.nvim.text.sort}", ":'<,'>sort") + ''; +} diff --git a/module/common/nvim/module/key/Telescope.nix b/module/common/nvim/module/key/Telescope.nix new file mode 100644 index 0000000..33ba3e2 --- /dev/null +++ b/module/common/nvim/module/key/Telescope.nix @@ -0,0 +1,12 @@ +{ key, ... }: let + mod = key.nvim.telescope.mod; +in { + text = '' + rekey_normal("${mod}${key.nvim.telescope.all}", "Telescope") + rekey_normal("${mod}${key.nvim.telescope.buffer}", "lua require('telescope.builtin').buffers()") + rekey_normal("${mod}${key.nvim.telescope.file}", "lua require('telescope.builtin').find_files()") + rekey_normal("${mod}${key.nvim.telescope.grep}", "lua require('telescope.builtin').live_grep()") + rekey_normal("${mod}${key.nvim.telescope.help}", "lua require('telescope.builtin').help_tags()") + rekey_normal("${mod}${key.nvim.telescope.treesitter}", "Telescope treesitter") + ''; +} diff --git a/module/common/nvim/module/key/Terminal.nix b/module/common/nvim/module/key/Terminal.nix new file mode 100644 index 0000000..5528d85 --- /dev/null +++ b/module/common/nvim/module/key/Terminal.nix @@ -0,0 +1,9 @@ +{ key, ... }: { + text = '' + -- Open terminal window. + rekey_normal("${key.nvim.window.terminal}", "terminal") + + -- Detach from terminal with Esc key. + rekey_terminal("", "") + ''; +} diff --git a/module/common/nvim/module/key/Todo.nix b/module/common/nvim/module/key/Todo.nix new file mode 100644 index 0000000..41c7d3e --- /dev/null +++ b/module/common/nvim/module/key/Todo.nix @@ -0,0 +1,6 @@ +{ key, ... }: { + text = '' + -- Toggle To-do window. + rekey_normal("${key.nvim.window.todo}", "TroubleToggle todo") + ''; +} diff --git a/module/common/nvim/module/key/Trouble.nix b/module/common/nvim/module/key/Trouble.nix new file mode 100644 index 0000000..5a36ed4 --- /dev/null +++ b/module/common/nvim/module/key/Trouble.nix @@ -0,0 +1,6 @@ +{ key, ... }: { + text = '' + -- Toggle diagnostics window. + rekey_normal("${key.nvim.window.trouble}", "TroubleToggle document_diagnostics") + ''; +} diff --git a/module/common/nvim/module/key/Whichkey.nix b/module/common/nvim/module/key/Whichkey.nix new file mode 100644 index 0000000..798ba94 --- /dev/null +++ b/module/common/nvim/module/key/Whichkey.nix @@ -0,0 +1,6 @@ +{ key, ... }: { + text = '' + -- Show keymap help. + rekey_normal("${key.nvim.window.whichkey}", "WhichKey") + ''; +} diff --git a/module/common/nvim/module/plugin/Align.nix b/module/common/nvim/module/plugin/Align.nix new file mode 100644 index 0000000..76bc586 --- /dev/null +++ b/module/common/nvim/module/plugin/Align.nix @@ -0,0 +1,10 @@ +{ ... }: { + text = '' + require("mini.align").setup { + mappings = { + start = "a", + -- start_with_preview = 'A', + }, + } + ''; +} diff --git a/module/common/nvim/module/plugin/Autoclose.nix b/module/common/nvim/module/plugin/Autoclose.nix new file mode 100644 index 0000000..d50e9f4 --- /dev/null +++ b/module/common/nvim/module/plugin/Autoclose.nix @@ -0,0 +1,17 @@ +{ ... }: { + text = '' + require("autoclose").setup({ + keys = { + ["'"] = { escape = false, close = false, pair = "''''''", disabled_filetypes = {} }, + ["("] = { escape = true, close = true, pair = "()", disabled_filetypes = {} }, + ["<"] = { escape = true, close = true, pair = "<>", disabled_filetypes = {} }, + ["\""] = { escape = true, close = true, pair = "\"\"", disabled_filetypes = {} }, + ["`"] = { escape = true, close = true, pair = "``", disabled_filetypes = {} }, + ["{"] = { escape = true, close = true, pair = "{}", disabled_filetypes = {} }, + }, + -- options = { + -- disabled_filetypes = { "text", "markdown" }, + -- } + }) + ''; +} diff --git a/module/common/nvim/module/plugin/Bufferline.nix b/module/common/nvim/module/plugin/Bufferline.nix new file mode 100644 index 0000000..13bb09a --- /dev/null +++ b/module/common/nvim/module/plugin/Bufferline.nix @@ -0,0 +1,5 @@ +{ ... }: { + text = '' + require("bufferline").setup() + ''; +} diff --git a/module/common/nvim/module/plugin/Closebuffers.nix b/module/common/nvim/module/plugin/Closebuffers.nix new file mode 100644 index 0000000..3aa1f0a --- /dev/null +++ b/module/common/nvim/module/plugin/Closebuffers.nix @@ -0,0 +1,11 @@ +{ ... }: { + text = '' + require("close_buffers").setup({ + file_glob_ignore = {}, + file_regex_ignore = {}, + filetype_ignore = {}, + next_buffer_cmd = nil, + preserve_window_layout = { "this", "nameless" }, + }) + ''; +} diff --git a/module/common/nvim/module/plugin/Colorizer.nix b/module/common/nvim/module/plugin/Colorizer.nix new file mode 100644 index 0000000..1554f84 --- /dev/null +++ b/module/common/nvim/module/plugin/Colorizer.nix @@ -0,0 +1,8 @@ +{ ... }: { + text = '' + -- Ensure termguicolors is enabled if not already + vim.opt.termguicolors = true + + require('nvim-highlight-colors').setup({}) + ''; +} diff --git a/module/common/nvim/module/plugin/Filetree.nix b/module/common/nvim/module/plugin/Filetree.nix new file mode 100644 index 0000000..7acbc96 --- /dev/null +++ b/module/common/nvim/module/plugin/Filetree.nix @@ -0,0 +1,40 @@ +{ ... }: { + text = '' + -- Disable netrw at the very start of your init.lua. + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + + local function my_on_attach(bufnr) + local api = require "nvim-tree.api" + + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + + -- Default mappings. + api.config.mappings.default_on_attach(bufnr) + + -- Custom mappings. + -- vim.keymap.set('n', '', api.tree.change_root_to_node, opts('Cd into')) + end + + -- Set termguicolors to enable highlight groups. + vim.opt.termguicolors = true + + -- Setup nvim-tree. + require("nvim-tree").setup({ + on_attach = my_on_attach, + sort_by = "case_sensitive", + view = { + width = 30, + }, + renderer = { + group_empty = true, + }, + filters = { + dotfiles = false, + git_ignored = false + }, + }) + ''; +} diff --git a/module/common/nvim/module/plugin/Fold.nix b/module/common/nvim/module/plugin/Fold.nix new file mode 100644 index 0000000..b67202c --- /dev/null +++ b/module/common/nvim/module/plugin/Fold.nix @@ -0,0 +1,7 @@ +{ ... }: { + text = '' + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + vim.opt.foldlevel = 99 + vim.opt.foldmethod = "expr" + ''; +} diff --git a/module/common/nvim/module/plugin/Gitsigns.nix b/module/common/nvim/module/plugin/Gitsigns.nix new file mode 100644 index 0000000..4a10896 --- /dev/null +++ b/module/common/nvim/module/plugin/Gitsigns.nix @@ -0,0 +1,47 @@ +{ ... }: { + text = '' + require("gitsigns").setup { + signs = { + add = { text = "│" }, + change = { text = "│" }, + changedelete = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + untracked = { text = "┆" }, + }, + linehl = false, + numhl = true, + signcolumn = false, + word_diff = false, + watch_gitdir = { + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = false, + current_line_blame_opts = { + delay = 1000, + ignore_whitespace = false, + virt_text = true, + virt_text_pos = "eol", + }, + current_line_blame_formatter = ", - ", + max_file_length = 40000, + sign_priority = 6, + status_formatter = nil, + update_debounce = 100, + preview_config = { + border = "single", + col = 1, + relative = "cursor", + row = 0, + style = "minimal", + }, + yadm = { + enable = false, + }, + } + + -- Set custom color. + vim.cmd("highlight gitsignscurrentlineblame guibg=#00000000 guifg=#aaaaaa") + ''; +} diff --git a/module/common/nvim/module/plugin/Gruvbox.nix b/module/common/nvim/module/plugin/Gruvbox.nix new file mode 100644 index 0000000..84b62d7 --- /dev/null +++ b/module/common/nvim/module/plugin/Gruvbox.nix @@ -0,0 +1,19 @@ +{ ... }: { + text = '' + vim.cmd([[ + if has('termguicolors') + set termguicolors + endif + ]]) + + vim.o.background = "dark" + vim.g.gruvbox_material_background = "hard" + vim.g.gruvbox_material_foreground = "original" + vim.g.gruvbox_material_transparent_background = 2 + -- vim.g.gruvbox_material_better_performance = 1 -- NOTE: Broken on NixOS. + + -- vim.cmd("autocmd ColorScheme * highlight Normal ctermbg=NONE guibg=NONE") + vim.cmd("colorscheme gruvbox-material") + vim.cmd("let g:lightline = {'colorscheme' : 'gruvbox_material'}") + ''; +} diff --git a/module/common/nvim/module/plugin/Indent.nix b/module/common/nvim/module/plugin/Indent.nix new file mode 100644 index 0000000..58280ca --- /dev/null +++ b/module/common/nvim/module/plugin/Indent.nix @@ -0,0 +1,10 @@ +{ ... }: { + text = '' + -- Auto-detect indentation type. + require("indent-o-matic").setup { + max_lines = 1024, + skip_multiline = true, + standard_widths = { 2, 4, 8 }, + } + ''; +} diff --git a/module/common/nvim/module/plugin/Init.nix b/module/common/nvim/module/plugin/Init.nix new file mode 100644 index 0000000..b85ed58 --- /dev/null +++ b/module/common/nvim/module/plugin/Init.nix @@ -0,0 +1,53 @@ +{ ... }: { + text = '' + local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim" + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({"git", "clone", "--depth", "1", "https://git.voronind.com/mirror/packer.nvim.git", install_path}) + vim.cmd [[packadd packer.nvim]] + return true + end + return false + end + + local packer_bootstrap = ensure_packer() + + local available = function(commands) + for _, command in ipairs(commands) do + if vim.fn.executable(command) ~= 1 then + return false + end + end + return true + end + + return require("packer").startup(function(use) + use "https://git.voronind.com/mirror/SingleComment.nvim.git" + use "https://git.voronind.com/mirror/autoclose.nvim.git" + use "https://git.voronind.com/mirror/bufferline.nvim.git" + use "https://git.voronind.com/mirror/close-buffers.nvim.git" + use "https://git.voronind.com/mirror/gitsigns.nvim.git" + use "https://git.voronind.com/mirror/gruvbox-material.git" + use "https://git.voronind.com/mirror/indent-o-matic.git" + use "https://git.voronind.com/mirror/lualine.nvim.git" + use "https://git.voronind.com/mirror/mini.align.git" + use "https://git.voronind.com/mirror/nvim-lspconfig.git" + use "https://git.voronind.com/mirror/nvim-tree.lua.git" + use "https://git.voronind.com/mirror/nvim-treesitter.git" + use "https://git.voronind.com/mirror/nvim-web-devicons.git" + use "https://git.voronind.com/mirror/packer.nvim.git" + use "https://git.voronind.com/mirror/plenary.nvim.git" + use "https://git.voronind.com/mirror/telescope.nvim.git" + use "https://git.voronind.com/mirror/todo-comments.nvim.git" + use "https://git.voronind.com/mirror/tokyonight.nvim.git" + use "https://git.voronind.com/mirror/trouble.nvim.git" + use "https://git.voronind.com/mirror/which-key.nvim.git" + + -- Auto-install. + if packer_bootstrap then + require("packer").sync() + end + end) + ''; +} diff --git a/module/common/nvim/module/plugin/Ollama.nix b/module/common/nvim/module/plugin/Ollama.nix new file mode 100644 index 0000000..e2be317 --- /dev/null +++ b/module/common/nvim/module/plugin/Ollama.nix @@ -0,0 +1,17 @@ +{ ... }: { + text = '' + require("ollama").setup { + model = "mistral", + url = "http://127.0.0.1:11434", + -- View the actual default prompts in ./lua/ollama/prompts.lua + prompts = { + -- Sample_Prompt = { + -- prompt = "This is a sample prompt that receives $input and $sel(ection), among others.", + -- input_label = "> ", + -- model = "mistral", + -- action = "display", + -- } + } + } + ''; +} diff --git a/module/common/nvim/module/plugin/Telescope.nix b/module/common/nvim/module/plugin/Telescope.nix new file mode 100644 index 0000000..f022420 --- /dev/null +++ b/module/common/nvim/module/plugin/Telescope.nix @@ -0,0 +1,15 @@ +{ ... }: { + text = '' + require("telescope").setup{ + defaults = { + mappings = { + i = { + [""] = "which_key", + } + } + }, + extensions = { }, + pickers = { }, + } + ''; +} diff --git a/module/common/nvim/module/plugin/Todo.nix b/module/common/nvim/module/plugin/Todo.nix new file mode 100644 index 0000000..d1f1beb --- /dev/null +++ b/module/common/nvim/module/plugin/Todo.nix @@ -0,0 +1,57 @@ +{ ... }: { + text = '' + require("todo-comments").setup { + sign_priority = 8, + signs = false, + keywords = { + FIX = { + alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, + color = "error", + icon = " ", + }, + HACK = { icon = " ", color = "warning" }, + NOTE = { icon = " ", color = "hint", alt = { "INFO" } }, + PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, + TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, + TODO = { icon = " ", color = "info" }, + WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, + }, + gui_style = { + bg = "BOLD", + fg = "NONE", + }, + merge_keywords = true, + highlight = { + after = "fg", + before = "", + comments_only = true, + exclude = {}, + keyword = "wide", + max_line_len = 400, + multiline = true, + multiline_context = 10, + multiline_pattern = "^.", + pattern = [[.*<(KEYWORDS)\s*:]], + }, + colors = { + default = { "Identifier", "#7C3AED" }, + error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, + hint = { "DiagnosticHint", "#10B981" }, + info = { "DiagnosticInfo", "#2563EB" }, + test = { "Identifier", "#FF00FF" }, + warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, + }, + search = { + command = "rg", + args = { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + }, + pattern = [[\b(KEYWORDS):]], + }, + } + ''; +} diff --git a/module/common/nvim/module/plugin/Tokyonight.nix b/module/common/nvim/module/plugin/Tokyonight.nix new file mode 100644 index 0000000..23e9b9e --- /dev/null +++ b/module/common/nvim/module/plugin/Tokyonight.nix @@ -0,0 +1,27 @@ +{ ... }: { + text = '' + require("tokyonight").setup({ + light_style = "night", + style = "night", + terminal_colors = true, + transparent = false, + styles = { + comments = { italic = true }, + floats = "dark", + functions = {}, + keywords = { italic = true }, + sidebars = "dark", + variables = {}, + }, + day_brightness = 0.3, + dim_inactive = false, + hide_inactive_statusline = false, + lualine_bold = false, + on_colors = function(colors) end, + on_highlights = function(highlights, colors) end, + sidebars = { "qf", "help" }, + }) + + -- vim.cmd[[colorscheme tokyonight]] + ''; +} diff --git a/module/common/nvim/module/plugin/Treesitter.nix b/module/common/nvim/module/plugin/Treesitter.nix new file mode 100644 index 0000000..c711d7c --- /dev/null +++ b/module/common/nvim/module/plugin/Treesitter.nix @@ -0,0 +1,25 @@ +{ ... }: { + text = '' + require("nvim-treesitter.configs").setup { + parser_install_dir = "~/.cache/nvim/treesitter", + auto_install = true, + -- ensure_installed = "all", + sync_install = false, + highlight = { + additional_vim_regex_highlighting = false, + enable = true, + use_languagetree = true, + disable = { "lua" }, + }, + indent = { + enable = true, + }, + autotag = { + enable = true + }, + rainbow = { + enable = true + }, + } + ''; +} diff --git a/module/common/nvim/module/plugin/Trouble.nix b/module/common/nvim/module/plugin/Trouble.nix new file mode 100644 index 0000000..73da358 --- /dev/null +++ b/module/common/nvim/module/plugin/Trouble.nix @@ -0,0 +1,5 @@ +{ ... }: { + text = '' + require("trouble").setup() + ''; +} diff --git a/module/common/nvim/module/plugin/lsp/Haskell.nix b/module/common/nvim/module/plugin/lsp/Haskell.nix new file mode 100644 index 0000000..676fbcd --- /dev/null +++ b/module/common/nvim/module/plugin/lsp/Haskell.nix @@ -0,0 +1,9 @@ +{ ... }: { + text = '' + local lspconfig = require("lspconfig") + + lspconfig.hls.setup { + filetypes = { 'haskell', 'lhaskell', 'cabal' }, + } + ''; +} diff --git a/module/common/nvim/module/plugin/lsp/Kotlin.nix b/module/common/nvim/module/plugin/lsp/Kotlin.nix new file mode 100644 index 0000000..5c71fbe --- /dev/null +++ b/module/common/nvim/module/plugin/lsp/Kotlin.nix @@ -0,0 +1,7 @@ +{ ... }: { + text = '' + local lspconfig = require("lspconfig") + + lspconfig.kotlin_language_server.setup {} + ''; +} diff --git a/module/common/nvim/module/plugin/lsp/Nix.nix b/module/common/nvim/module/plugin/lsp/Nix.nix new file mode 100644 index 0000000..e3f511f --- /dev/null +++ b/module/common/nvim/module/plugin/lsp/Nix.nix @@ -0,0 +1,7 @@ +{ ... }: { + text = '' + local lspconfig = require("lspconfig") + + lspconfig.nixd.setup {} + ''; +} diff --git a/module/common/nvim/module/plugin/lsp/Python.nix b/module/common/nvim/module/plugin/lsp/Python.nix new file mode 100644 index 0000000..7019fbc --- /dev/null +++ b/module/common/nvim/module/plugin/lsp/Python.nix @@ -0,0 +1,7 @@ +{ ... }: { + text = '' + local lspconfig = require("lspconfig") + + lspconfig.pyright.setup {} + ''; +} diff --git a/module/common/nvim/module/plugin/lsp/Rust.nix b/module/common/nvim/module/plugin/lsp/Rust.nix new file mode 100644 index 0000000..f9cc4c6 --- /dev/null +++ b/module/common/nvim/module/plugin/lsp/Rust.nix @@ -0,0 +1,20 @@ +{ ... }: { + text = '' + local lspconfig = require("lspconfig") + + lspconfig.rust_analyzer.setup { + settings = { + ["rust-analyzer"] = { + rustfmt = { + extraArgs = { + "--config", + "hard_tabs=true", + } + } + }, + }, + } + + vim.g.rust_recommended_style = false + ''; +} diff --git a/module/common/nvim/module/plugin/lsp/Tex.nix b/module/common/nvim/module/plugin/lsp/Tex.nix new file mode 100644 index 0000000..783eefd --- /dev/null +++ b/module/common/nvim/module/plugin/lsp/Tex.nix @@ -0,0 +1,64 @@ +{ ... }: { + text = '' + local lspconfig = require('lspconfig') + local config = { + filetypes = { + "bib", + "gitcommit", + "markdown", + "org", + "pandoc", + "plaintex", + "rnoweb", + "rst", + "tex", + "text", + }, + settings = { + ["ltex"] = { + language = "auto" + } + } + } + + lspconfig.ltex.setup(config) + + -- Use TeX LSP for spellcheck. + vim.api.nvim_create_user_command("SCOn", function (args) + lspconfig.ltex.setup(config) + end, { desc = "Enable spellcheck." }) + + vim.api.nvim_create_user_command("SCOff", function (args) + lspconfig.ltex.setup { filetypes = {} } + end, { desc = "Disable spellcheck." }) + + vim.api.nvim_create_user_command("SCLangRU", function (args) + config.settings['ltex'].language = "ru-RU" + lspconfig.ltex.setup(config) + end, { desc = "Set spellcheck to Russian." }) + + vim.api.nvim_create_user_command("SCLangEN", function (args) + config.settings['ltex'].language = "en-US" + lspconfig.ltex.setup(config) + end, { desc = "Set spellcheck to English." }) + + vim.api.nvim_create_user_command("SCLangAuto", function (args) + config.settings['ltex'].language = "auto" + lspconfig.ltex.setup(config) + end, { desc = "Set spellcheck to Auto." }) + + vim.api.nvim_create_user_command("SCForce", function (args) + vim.cmd("setfiletype text") + vim.cmd("SCOn") + end, { desc = "Set buffer type to text." }) + + vim.api.nvim_create_user_command("SCReset", function (args) + vim.cmd("filetype detect") + vim.cmd("SCLangAuto") + end, { desc = "Set buffer type to auto." }) + + vim.api.nvim_create_user_command("SCInfo", function (args) + vim.cmd("LspInfo") + end, { desc = "Show info about spellcheck." }) + ''; +} diff --git a/module/common/nvim/src/config/Autoread.lua b/module/common/nvim/src/config/Autoread.lua deleted file mode 100644 index bc9a40c..0000000 --- a/module/common/nvim/src/config/Autoread.lua +++ /dev/null @@ -1,5 +0,0 @@ -vim.o.autoread = true -vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "CursorHoldI", "FocusGained" }, { - command = "if mode() != 'c' | checktime | endif", - pattern = { "*" }, -}) diff --git a/module/common/nvim/src/config/Etc.lua b/module/common/nvim/src/config/Etc.lua deleted file mode 100644 index e9336bb..0000000 --- a/module/common/nvim/src/config/Etc.lua +++ /dev/null @@ -1,27 +0,0 @@ --- TODO: Add comments and separate files. -vim.opt.clipboard = "unnamedplus" --- vim.opt.completeopt = "menuone,noselect" -vim.opt.cursorline = false -vim.opt.fixeol = false -vim.opt.number = true -vim.opt.splitbelow = true -vim.opt.splitright = true -vim.opt.termguicolors = true -vim.opt.ttyfast = true -vim.opt.wildmode = "longest,list" - --- Disable continuing comments on newline. -vim.cmd("autocmd BufEnter * set fo-=c fo-=r fo-=o") - --- Disable mouse. -vim.cmd("set mouse=") - --- Disable signs for diagnostics. -vim.diagnostic.config({ signs = false }) - --- Display invisible characters. --- vim.cmd("set list listchars=tab:>\\ ,trail:-,eol:,lead:.") -vim.cmd("set list listchars=tab:>\\ ,trail:-,lead:.") - --- Relative line numbers. -vim.wo.relativenumber = true diff --git a/module/common/nvim/src/config/Search.lua b/module/common/nvim/src/config/Search.lua deleted file mode 100644 index 08e709e..0000000 --- a/module/common/nvim/src/config/Search.lua +++ /dev/null @@ -1,5 +0,0 @@ -vim.opt.hlsearch = true -vim.opt.ignorecase = true -vim.opt.incsearch = true -vim.opt.showmatch = true -vim.opt.smartcase = true diff --git a/module/common/nvim/src/config/Tab.lua b/module/common/nvim/src/config/Tab.lua deleted file mode 100644 index ef4af91..0000000 --- a/module/common/nvim/src/config/Tab.lua +++ /dev/null @@ -1,9 +0,0 @@ -vim.opt.autoindent = true -vim.opt.expandtab = false -vim.opt.shiftwidth = 2 --- vim.opt.smartindent = true -vim.opt.softtabstop = 2 -vim.opt.tabstop = 2 - --- Disable Markdown forced formatting. -vim.g.markdown_recommended_style = 0 diff --git a/module/common/nvim/src/key/Autocomplete.lua b/module/common/nvim/src/key/Autocomplete.lua deleted file mode 100644 index ad9ee38..0000000 --- a/module/common/nvim/src/key/Autocomplete.lua +++ /dev/null @@ -1,5 +0,0 @@ --- Autocomplete. -rekey_input("", "") - --- LSP autocomplete. -rekey_normal("", "lua vim.lsp.buf.code_action()") diff --git a/module/common/nvim/src/key/Buffer.lua b/module/common/nvim/src/key/Buffer.lua deleted file mode 100644 index 9c2f977..0000000 --- a/module/common/nvim/src/key/Buffer.lua +++ /dev/null @@ -1,12 +0,0 @@ --- New empty buffer. -remap_normal("n", "enew") - --- Close buffer. -function _buf_close() - pcall(vim.cmd, "w") - vim.cmd[[bp|sp|bn|bd!]] -end -rekey_normal("x", "lua _buf_close()") - --- Close all hidden buffers. -rekey_normal("X", "BDelete hidden") diff --git a/module/common/nvim/src/key/Colorscheme.lua b/module/common/nvim/src/key/Colorscheme.lua deleted file mode 100644 index 374fe32..0000000 --- a/module/common/nvim/src/key/Colorscheme.lua +++ /dev/null @@ -1,22 +0,0 @@ -function toggle_contrast() - if vim.g.gruvbox_material_background == "light" then - vim.g.gruvbox_material_background = "medium" - elseif vim.g.gruvbox_material_background == "medium" then - vim.g.gruvbox_material_background = "hard" - elseif vim.g.gruvbox_material_background == "hard" then - vim.g.gruvbox_material_background = "light" - end - vim.cmd("colorscheme gruvbox-material") -end - -function toggle_light() - if vim.o.background == "light" then - vim.o.background = "dark" - elseif vim.o.background == "dark" then - vim.o.background = "light" - end - -- require("lualine").setup() -end - -rekey_normal("[", "lua toggle_contrast()") -rekey_normal("]", "lua toggle_light()") diff --git a/module/common/nvim/src/key/Comment.lua b/module/common/nvim/src/key/Comment.lua deleted file mode 100644 index 3991e1d..0000000 --- a/module/common/nvim/src/key/Comment.lua +++ /dev/null @@ -1,5 +0,0 @@ --- Toggle comment for the selected line. -vim.keymap.set("n", "/", require("SingleComment").SingleComment, { expr = true }) - --- Toggle comments for multiple lines. -vim.keymap.set("v", "/", require("SingleComment").Comment, {}) diff --git a/module/common/nvim/src/key/Common.lua b/module/common/nvim/src/key/Common.lua deleted file mode 100644 index 9e6fb31..0000000 --- a/module/common/nvim/src/key/Common.lua +++ /dev/null @@ -1,40 +0,0 @@ --- Write all we can and exit. Created this to drop non-writable stuff when piping to nvim. -function bye() - pcall(vim.cmd, "wa") - vim.cmd[[qa!]] -end - -function toggle_tab_width() - if vim.bo.shiftwidth == 2 then - vim.bo.shiftwidth = 4 - vim.bo.tabstop = 4 - vim.bo.softtabstop = 4 - elseif vim.bo.shiftwidth == 4 then - vim.bo.shiftwidth = 8 - vim.bo.tabstop = 8 - vim.bo.softtabstop = 8 - elseif vim.bo.shiftwidth == 8 then - vim.bo.shiftwidth = 2 - vim.bo.tabstop = 2 - vim.bo.softtabstop = 2 - end -end - -rekey_normal("", "lua toggle_tab_width()") - --- Repeat previous command. -rekey_normal(".", "@:") -rekey_visual(".", "@:") - --- Save everything. -rekey_normal("zz", "wa") - --- Save all we can and leave. -rekey_normal("z", "lua bye()") - --- Compatibility alias for visual selection. -rekey_normal("v", "v") - --- Remap ; to :. -rekey_normal(";", ":") -rekey_visual(";", ":") diff --git a/module/common/nvim/src/key/Filetree.lua b/module/common/nvim/src/key/Filetree.lua deleted file mode 100644 index fe19a3e..0000000 --- a/module/common/nvim/src/key/Filetree.lua +++ /dev/null @@ -1,2 +0,0 @@ --- Toggle file tree. -rekey_normal("1", "NvimTreeToggle") diff --git a/module/common/nvim/src/key/Gitsigns.lua b/module/common/nvim/src/key/Gitsigns.lua deleted file mode 100644 index dffa62b..0000000 --- a/module/common/nvim/src/key/Gitsigns.lua +++ /dev/null @@ -1,2 +0,0 @@ --- Toggle Git inspection mode. -rekey_normal("g", "Gitsigns toggle_current_line_blameGitsigns toggle_word_diffGitsigns toggle_linehl") diff --git a/module/common/nvim/src/key/Leader.lua b/module/common/nvim/src/key/Leader.lua deleted file mode 100644 index b99ec09..0000000 --- a/module/common/nvim/src/key/Leader.lua +++ /dev/null @@ -1,7 +0,0 @@ -leader = " " - -vim.g.mapleader = leader -vim.g.maplocalleader = leader - --- Disable key press timeout. -vim.cmd("set notimeout nottimeout") diff --git a/module/common/nvim/src/key/Lsp.lua b/module/common/nvim/src/key/Lsp.lua deleted file mode 100644 index e69de29..0000000 diff --git a/module/common/nvim/src/key/Navigation.lua b/module/common/nvim/src/key/Navigation.lua deleted file mode 100644 index 2b08f39..0000000 --- a/module/common/nvim/src/key/Navigation.lua +++ /dev/null @@ -1,29 +0,0 @@ --- Switch windows. -rekey_normal("a", "h") -rekey_normal("d", "l") -rekey_normal("s", "j") -rekey_normal("w", "k") - --- Switch buffers. -rekey_normal("E", "BufferLineMoveNext") -rekey_normal("Q", "BufferLineMovePrev") -rekey_normal("e", "BufferLineCycleNext") -rekey_normal("q", "BufferLineCyclePrev") - --- Splits. -rekey_normal("\\", "vsplit") -rekey_normal("-", "split") -rekey_normal("=", "=") -- Equalize split sizes. -rekey_normal("c", "q") -- Close split. - --- Resize splits. -rekey_normal("h", "4<") -rekey_normal("l", "4>") -rekey_normal("j", "2+") -rekey_normal("k", "2-") - --- Move splits. -rekey_normal("A", "A") -rekey_normal("D", "D") -rekey_normal("S", "S") -rekey_normal("W", "W") diff --git a/module/common/nvim/src/key/Ollama.lua b/module/common/nvim/src/key/Ollama.lua deleted file mode 100644 index 486e3eb..0000000 --- a/module/common/nvim/src/key/Ollama.lua +++ /dev/null @@ -1,2 +0,0 @@ -rekey_normal("p", ":lua require('ollama').prompt()") -rekey_visual("p", ":lua require('ollama').prompt()") diff --git a/module/common/nvim/src/key/Rekey.lua b/module/common/nvim/src/key/Rekey.lua deleted file mode 100644 index 314e975..0000000 --- a/module/common/nvim/src/key/Rekey.lua +++ /dev/null @@ -1,49 +0,0 @@ --- Base rekey function. -local function rekey(t, key, command) - vim.api.nvim_set_keymap(t, key, command, { noremap = true }) -end - --- Base remap function. -local function remap(t, key, command) - vim.api.nvim_set_keymap(t, key, command, { noremap = false }) -end - --- Rekey in normal mode. -function rekey_normal(key, command) - rekey("n", key, command) -end - --- Rekey in input mode. -function rekey_input(key, command) - rekey("i", key, command) -end - --- Rekey in visual mode. -function rekey_visual(key, command) - rekey("v", key, command) -end - --- Rekey in terminal mode. -function rekey_terminal(key, command) - rekey("t", key, command) -end - --- Remap in normal mode. -function remap_normal(key, command) - remap("n", key, command) -end - --- Remap in input mode. -function remap_input(key, command) - remap("i", key, command) -end - --- Remap in visual mode. -function remap_visual(key, command) - remap("v", key, command) -end - --- Remap in terminal mode. -function remap_terminal(key, command) - remap("t", key, command) -end diff --git a/module/common/nvim/src/key/Sort.lua b/module/common/nvim/src/key/Sort.lua deleted file mode 100644 index 3b234ef..0000000 --- a/module/common/nvim/src/key/Sort.lua +++ /dev/null @@ -1,2 +0,0 @@ --- Sort visual selection alphabetically. -rekey_visual("A", ":'<,'>sort") diff --git a/module/common/nvim/src/key/Telescope.lua b/module/common/nvim/src/key/Telescope.lua deleted file mode 100644 index b747f5e..0000000 --- a/module/common/nvim/src/key/Telescope.lua +++ /dev/null @@ -1,6 +0,0 @@ -rekey_normal("fa", "Telescope") -rekey_normal("fb", "lua require('telescope.builtin').buffers()") -rekey_normal("ff", "lua require('telescope.builtin').find_files()") -rekey_normal("fg", "lua require('telescope.builtin').live_grep()") -rekey_normal("fh", "lua require('telescope.builtin').help_tags()") -rekey_normal("ft", "Telescope treesitter") diff --git a/module/common/nvim/src/key/Terminal.lua b/module/common/nvim/src/key/Terminal.lua deleted file mode 100644 index 359cc74..0000000 --- a/module/common/nvim/src/key/Terminal.lua +++ /dev/null @@ -1,5 +0,0 @@ --- Open terminal window. -rekey_normal("4", "terminal") - --- Detach from terminal with Esc key. -rekey_terminal("", "") diff --git a/module/common/nvim/src/key/Todo.lua b/module/common/nvim/src/key/Todo.lua deleted file mode 100644 index 7e84da8..0000000 --- a/module/common/nvim/src/key/Todo.lua +++ /dev/null @@ -1,2 +0,0 @@ --- Toggle To-do window. -rekey_normal("3", "TroubleToggle todo") diff --git a/module/common/nvim/src/key/Trouble.lua b/module/common/nvim/src/key/Trouble.lua deleted file mode 100644 index ea948e8..0000000 --- a/module/common/nvim/src/key/Trouble.lua +++ /dev/null @@ -1,2 +0,0 @@ --- Toggle diagnostics window. -rekey_normal("2", "TroubleToggle document_diagnostics") diff --git a/module/common/nvim/src/key/Update.lua b/module/common/nvim/src/key/Update.lua deleted file mode 100644 index f2fcca6..0000000 --- a/module/common/nvim/src/key/Update.lua +++ /dev/null @@ -1,5 +0,0 @@ --- Update all command. -vim.api.nvim_create_user_command("Update", function (args) - vim.cmd("PackerUpdate") - vim.cmd("TSUpdate") -end, { desc = "Update everything." }) diff --git a/module/common/nvim/src/key/Whichkey.lua b/module/common/nvim/src/key/Whichkey.lua deleted file mode 100644 index afb61aa..0000000 --- a/module/common/nvim/src/key/Whichkey.lua +++ /dev/null @@ -1,2 +0,0 @@ --- Show keymap help. -rekey_normal("?", "WhichKey") diff --git a/module/common/nvim/src/plugin/Align.lua b/module/common/nvim/src/plugin/Align.lua deleted file mode 100644 index 7db2b57..0000000 --- a/module/common/nvim/src/plugin/Align.lua +++ /dev/null @@ -1,7 +0,0 @@ -require("mini.align").setup { - mappings = { - start = "a", - -- start_with_preview = 'A', - }, -} - diff --git a/module/common/nvim/src/plugin/Autoclose.lua b/module/common/nvim/src/plugin/Autoclose.lua deleted file mode 100644 index e932054..0000000 --- a/module/common/nvim/src/plugin/Autoclose.lua +++ /dev/null @@ -1,13 +0,0 @@ -require("autoclose").setup({ - keys = { - ["'"] = { escape = false, close = false, pair = "''", disabled_filetypes = {} }, - ["("] = { escape = true, close = true, pair = "()", disabled_filetypes = {} }, - ["<"] = { escape = true, close = true, pair = "<>", disabled_filetypes = {} }, - ["\""] = { escape = true, close = true, pair = "\"\"", disabled_filetypes = {} }, - ["`"] = { escape = true, close = true, pair = "``", disabled_filetypes = {} }, - ["{"] = { escape = true, close = true, pair = "{}", disabled_filetypes = {} }, - }, - -- options = { - -- disabled_filetypes = { "text", "markdown" }, - -- } -}) diff --git a/module/common/nvim/src/plugin/Bufferline.lua b/module/common/nvim/src/plugin/Bufferline.lua deleted file mode 100644 index da65645..0000000 --- a/module/common/nvim/src/plugin/Bufferline.lua +++ /dev/null @@ -1 +0,0 @@ -require("bufferline").setup() diff --git a/module/common/nvim/src/plugin/Closebuffers.lua b/module/common/nvim/src/plugin/Closebuffers.lua deleted file mode 100644 index a1f2906..0000000 --- a/module/common/nvim/src/plugin/Closebuffers.lua +++ /dev/null @@ -1,7 +0,0 @@ -require("close_buffers").setup({ - file_glob_ignore = {}, - file_regex_ignore = {}, - filetype_ignore = {}, - next_buffer_cmd = nil, - preserve_window_layout = { "this", "nameless" }, -}) diff --git a/module/common/nvim/src/plugin/Colorizer.lua b/module/common/nvim/src/plugin/Colorizer.lua deleted file mode 100644 index f2bad37..0000000 --- a/module/common/nvim/src/plugin/Colorizer.lua +++ /dev/null @@ -1,4 +0,0 @@ --- Ensure termguicolors is enabled if not already -vim.opt.termguicolors = true - -require('nvim-highlight-colors').setup({}) diff --git a/module/common/nvim/src/plugin/Filetree.lua b/module/common/nvim/src/plugin/Filetree.lua deleted file mode 100644 index a9eb87d..0000000 --- a/module/common/nvim/src/plugin/Filetree.lua +++ /dev/null @@ -1,36 +0,0 @@ --- Disable netrw at the very start of your init.lua. -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 - -local function my_on_attach(bufnr) - local api = require "nvim-tree.api" - - local function opts(desc) - return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } - end - - -- Default mappings. - api.config.mappings.default_on_attach(bufnr) - - -- Custom mappings. - -- vim.keymap.set('n', '', api.tree.change_root_to_node, opts('Cd into')) -end - --- Set termguicolors to enable highlight groups. -vim.opt.termguicolors = true - --- Setup nvim-tree. -require("nvim-tree").setup({ - on_attach = my_on_attach, - sort_by = "case_sensitive", - view = { - width = 30, - }, - renderer = { - group_empty = true, - }, - filters = { - dotfiles = false, - git_ignored = false - }, -}) diff --git a/module/common/nvim/src/plugin/Fold.lua b/module/common/nvim/src/plugin/Fold.lua deleted file mode 100644 index b088a28..0000000 --- a/module/common/nvim/src/plugin/Fold.lua +++ /dev/null @@ -1,3 +0,0 @@ -vim.opt.foldexpr = "nvim_treesitter#foldexpr()" -vim.opt.foldlevel = 99 -vim.opt.foldmethod = "expr" diff --git a/module/common/nvim/src/plugin/Gitsigns.lua b/module/common/nvim/src/plugin/Gitsigns.lua deleted file mode 100644 index c26b670..0000000 --- a/module/common/nvim/src/plugin/Gitsigns.lua +++ /dev/null @@ -1,43 +0,0 @@ -require("gitsigns").setup { - signs = { - add = { text = "│" }, - change = { text = "│" }, - changedelete = { text = "~" }, - delete = { text = "_" }, - topdelete = { text = "‾" }, - untracked = { text = "┆" }, - }, - linehl = false, - numhl = true, - signcolumn = false, - word_diff = false, - watch_gitdir = { - follow_files = true, - }, - attach_to_untracked = true, - current_line_blame = false, - current_line_blame_opts = { - delay = 1000, - ignore_whitespace = false, - virt_text = true, - virt_text_pos = "eol", - }, - current_line_blame_formatter = ", - ", - max_file_length = 40000, - sign_priority = 6, - status_formatter = nil, - update_debounce = 100, - preview_config = { - border = "single", - col = 1, - relative = "cursor", - row = 0, - style = "minimal", - }, - yadm = { - enable = false, - }, -} - --- Set custom color. -vim.cmd("highlight gitsignscurrentlineblame guibg=#00000000 guifg=#aaaaaa") diff --git a/module/common/nvim/src/plugin/Gruvbox.lua b/module/common/nvim/src/plugin/Gruvbox.lua deleted file mode 100644 index 54f618e..0000000 --- a/module/common/nvim/src/plugin/Gruvbox.lua +++ /dev/null @@ -1,15 +0,0 @@ -vim.cmd([[ - if has('termguicolors') - set termguicolors - endif -]]) - -vim.o.background = "dark" -vim.g.gruvbox_material_background = "hard" -vim.g.gruvbox_material_foreground = "original" -vim.g.gruvbox_material_transparent_background = 2 --- vim.g.gruvbox_material_better_performance = 1 -- NOTE: Broken on NixOS. - --- vim.cmd("autocmd ColorScheme * highlight Normal ctermbg=NONE guibg=NONE") -vim.cmd("colorscheme gruvbox-material") -vim.cmd("let g:lightline = {'colorscheme' : 'gruvbox_material'}") diff --git a/module/common/nvim/src/plugin/Indent.lua b/module/common/nvim/src/plugin/Indent.lua deleted file mode 100644 index 279f4f7..0000000 --- a/module/common/nvim/src/plugin/Indent.lua +++ /dev/null @@ -1,6 +0,0 @@ --- Auto-detect indentation type. -require("indent-o-matic").setup { - max_lines = 1024, - skip_multiline = true, - standard_widths = { 2, 4, 8 }, -} diff --git a/module/common/nvim/src/plugin/Init.lua b/module/common/nvim/src/plugin/Init.lua deleted file mode 100644 index 8394b1a..0000000 --- a/module/common/nvim/src/plugin/Init.lua +++ /dev/null @@ -1,49 +0,0 @@ -local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim" - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({"git", "clone", "--depth", "1", "https://git.voronind.com/mirror/packer.nvim.git", install_path}) - vim.cmd [[packadd packer.nvim]] - return true - end - return false -end - -local packer_bootstrap = ensure_packer() - -local available = function(commands) - for _, command in ipairs(commands) do - if vim.fn.executable(command) ~= 1 then - return false - end - end - return true -end - -return require("packer").startup(function(use) - use "https://git.voronind.com/mirror/SingleComment.nvim.git" - use "https://git.voronind.com/mirror/autoclose.nvim.git" - use "https://git.voronind.com/mirror/bufferline.nvim.git" - use "https://git.voronind.com/mirror/close-buffers.nvim.git" - use "https://git.voronind.com/mirror/gitsigns.nvim.git" - use "https://git.voronind.com/mirror/gruvbox-material.git" - use "https://git.voronind.com/mirror/indent-o-matic.git" - use "https://git.voronind.com/mirror/lualine.nvim.git" - use "https://git.voronind.com/mirror/mini.align.git" - use "https://git.voronind.com/mirror/nvim-lspconfig.git" - use "https://git.voronind.com/mirror/nvim-tree.lua.git" - use "https://git.voronind.com/mirror/nvim-treesitter.git" - use "https://git.voronind.com/mirror/nvim-web-devicons.git" - use "https://git.voronind.com/mirror/packer.nvim.git" - use "https://git.voronind.com/mirror/plenary.nvim.git" - use "https://git.voronind.com/mirror/telescope.nvim.git" - use "https://git.voronind.com/mirror/todo-comments.nvim.git" - use "https://git.voronind.com/mirror/tokyonight.nvim.git" - use "https://git.voronind.com/mirror/trouble.nvim.git" - use "https://git.voronind.com/mirror/which-key.nvim.git" - - -- Auto-install. - if packer_bootstrap then - require("packer").sync() - end -end) diff --git a/module/common/nvim/src/plugin/Ollama.lua b/module/common/nvim/src/plugin/Ollama.lua deleted file mode 100644 index 7f55544..0000000 --- a/module/common/nvim/src/plugin/Ollama.lua +++ /dev/null @@ -1,13 +0,0 @@ -require("ollama").setup { - model = "mistral", - url = "http://127.0.0.1:11434", - -- View the actual default prompts in ./lua/ollama/prompts.lua - prompts = { - -- Sample_Prompt = { - -- prompt = "This is a sample prompt that receives $input and $sel(ection), among others.", - -- input_label = "> ", - -- model = "mistral", - -- action = "display", - -- } - } -} diff --git a/module/common/nvim/src/plugin/Telescope.lua b/module/common/nvim/src/plugin/Telescope.lua deleted file mode 100644 index d30fb98..0000000 --- a/module/common/nvim/src/plugin/Telescope.lua +++ /dev/null @@ -1,11 +0,0 @@ -require("telescope").setup{ - defaults = { - mappings = { - i = { - [""] = "which_key", - } - } - }, - extensions = { }, - pickers = { }, -} diff --git a/module/common/nvim/src/plugin/Todo.lua b/module/common/nvim/src/plugin/Todo.lua deleted file mode 100644 index e583a45..0000000 --- a/module/common/nvim/src/plugin/Todo.lua +++ /dev/null @@ -1,53 +0,0 @@ -require("todo-comments").setup { - sign_priority = 8, - signs = false, - keywords = { - FIX = { - alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, - color = "error", - icon = " ", - }, - HACK = { icon = " ", color = "warning" }, - NOTE = { icon = " ", color = "hint", alt = { "INFO" } }, - PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, - TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, - TODO = { icon = " ", color = "info" }, - WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, - }, - gui_style = { - bg = "BOLD", - fg = "NONE", - }, - merge_keywords = true, - highlight = { - after = "fg", - before = "", - comments_only = true, - exclude = {}, - keyword = "wide", - max_line_len = 400, - multiline = true, - multiline_context = 10, - multiline_pattern = "^.", - pattern = [[.*<(KEYWORDS)\s*:]], - }, - colors = { - default = { "Identifier", "#7C3AED" }, - error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, - hint = { "DiagnosticHint", "#10B981" }, - info = { "DiagnosticInfo", "#2563EB" }, - test = { "Identifier", "#FF00FF" }, - warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, - }, - search = { - command = "rg", - args = { - "--color=never", - "--no-heading", - "--with-filename", - "--line-number", - "--column", - }, - pattern = [[\b(KEYWORDS):]], - }, -} diff --git a/module/common/nvim/src/plugin/Tokyonight.lua b/module/common/nvim/src/plugin/Tokyonight.lua deleted file mode 100644 index 667ee34..0000000 --- a/module/common/nvim/src/plugin/Tokyonight.lua +++ /dev/null @@ -1,23 +0,0 @@ -require("tokyonight").setup({ - light_style = "night", - style = "night", - terminal_colors = true, - transparent = false, - styles = { - comments = { italic = true }, - floats = "dark", - functions = {}, - keywords = { italic = true }, - sidebars = "dark", - variables = {}, - }, - day_brightness = 0.3, - dim_inactive = false, - hide_inactive_statusline = false, - lualine_bold = false, - on_colors = function(colors) end, - on_highlights = function(highlights, colors) end, - sidebars = { "qf", "help" }, -}) - --- vim.cmd[[colorscheme tokyonight]] diff --git a/module/common/nvim/src/plugin/Treesitter.lua b/module/common/nvim/src/plugin/Treesitter.lua deleted file mode 100644 index efbcff2..0000000 --- a/module/common/nvim/src/plugin/Treesitter.lua +++ /dev/null @@ -1,21 +0,0 @@ -require("nvim-treesitter.configs").setup { - parser_install_dir = "~/.cache/nvim/treesitter", - auto_install = true, - -- ensure_installed = "all", - sync_install = false, - highlight = { - additional_vim_regex_highlighting = false, - enable = true, - use_languagetree = true, - disable = { "lua" }, - }, - indent = { - enable = true, - }, - autotag = { - enable = true - }, - rainbow = { - enable = true - }, -} diff --git a/module/common/nvim/src/plugin/Trouble.lua b/module/common/nvim/src/plugin/Trouble.lua deleted file mode 100644 index 38ef1e9..0000000 --- a/module/common/nvim/src/plugin/Trouble.lua +++ /dev/null @@ -1 +0,0 @@ -require("trouble").setup() diff --git a/module/common/nvim/src/plugin/lsp/Haskell.lua b/module/common/nvim/src/plugin/lsp/Haskell.lua deleted file mode 100644 index fdab951..0000000 --- a/module/common/nvim/src/plugin/lsp/Haskell.lua +++ /dev/null @@ -1,5 +0,0 @@ -local lspconfig = require("lspconfig") - -lspconfig.hls.setup { - filetypes = { 'haskell', 'lhaskell', 'cabal' }, -} diff --git a/module/common/nvim/src/plugin/lsp/Kotlin.lua b/module/common/nvim/src/plugin/lsp/Kotlin.lua deleted file mode 100644 index e960df6..0000000 --- a/module/common/nvim/src/plugin/lsp/Kotlin.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lspconfig = require("lspconfig") - -lspconfig.kotlin_language_server.setup {} diff --git a/module/common/nvim/src/plugin/lsp/Nix.lua b/module/common/nvim/src/plugin/lsp/Nix.lua deleted file mode 100644 index 6d6afc5..0000000 --- a/module/common/nvim/src/plugin/lsp/Nix.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lspconfig = require("lspconfig") - -lspconfig.nixd.setup {} diff --git a/module/common/nvim/src/plugin/lsp/Python.lua b/module/common/nvim/src/plugin/lsp/Python.lua deleted file mode 100644 index 5642869..0000000 --- a/module/common/nvim/src/plugin/lsp/Python.lua +++ /dev/null @@ -1,3 +0,0 @@ -local lspconfig = require("lspconfig") - -lspconfig.pyright.setup {} diff --git a/module/common/nvim/src/plugin/lsp/Rust.lua b/module/common/nvim/src/plugin/lsp/Rust.lua deleted file mode 100644 index 2ca5362..0000000 --- a/module/common/nvim/src/plugin/lsp/Rust.lua +++ /dev/null @@ -1,16 +0,0 @@ -local lspconfig = require("lspconfig") - -lspconfig.rust_analyzer.setup { - settings = { - ["rust-analyzer"] = { - rustfmt = { - extraArgs = { - "--config", - "hard_tabs=true", - } - } - }, - }, -} - -vim.g.rust_recommended_style = false diff --git a/module/common/nvim/src/plugin/lsp/Tex.lua b/module/common/nvim/src/plugin/lsp/Tex.lua deleted file mode 100644 index bc0fb7a..0000000 --- a/module/common/nvim/src/plugin/lsp/Tex.lua +++ /dev/null @@ -1,60 +0,0 @@ -local lspconfig = require('lspconfig') -local config = { - filetypes = { - "bib", - "gitcommit", - "markdown", - "org", - "pandoc", - "plaintex", - "rnoweb", - "rst", - "tex", - "text", - }, - settings = { - ["ltex"] = { - language = "auto" - } - } -} - -lspconfig.ltex.setup(config) - --- Use TeX LSP for spellcheck. -vim.api.nvim_create_user_command("SCOn", function (args) - lspconfig.ltex.setup(config) -end, { desc = "Enable spellcheck." }) - -vim.api.nvim_create_user_command("SCOff", function (args) - lspconfig.ltex.setup { filetypes = {} } -end, { desc = "Disable spellcheck." }) - -vim.api.nvim_create_user_command("SCLangRU", function (args) - config.settings['ltex'].language = "ru-RU" - lspconfig.ltex.setup(config) -end, { desc = "Set spellcheck to Russian." }) - -vim.api.nvim_create_user_command("SCLangEN", function (args) - config.settings['ltex'].language = "en-US" - lspconfig.ltex.setup(config) -end, { desc = "Set spellcheck to English." }) - -vim.api.nvim_create_user_command("SCLangAuto", function (args) - config.settings['ltex'].language = "auto" - lspconfig.ltex.setup(config) -end, { desc = "Set spellcheck to Auto." }) - -vim.api.nvim_create_user_command("SCForce", function (args) - vim.cmd("setfiletype text") - vim.cmd("SCOn") -end, { desc = "Set buffer type to text." }) - -vim.api.nvim_create_user_command("SCReset", function (args) - vim.cmd("filetype detect") - vim.cmd("SCLangAuto") -end, { desc = "Set buffer type to auto." }) - -vim.api.nvim_create_user_command("SCInfo", function (args) - vim.cmd("LspInfo") -end, { desc = "Show info about spellcheck." }) diff --git a/module/common/ssh/Init.nix b/module/common/ssh/Init.nix new file mode 100644 index 0000000..fe42694 --- /dev/null +++ b/module/common/ssh/Init.nix @@ -0,0 +1,48 @@ +{ util, ... }: { + config = util.trimTabs '' + Host dasha + HostName 192.168.1.7 + User root + Port 22143 + + Host desktop + Hostname 192.168.1.3 + User root + Port 22143 + + Host fmpmaven + Hostname 10.30.22.10 + User root + Port 22 + + Host fsight + Hostname 10.30.217.25 + User root + Port 22143 + + Host home + HostName 192.168.1.2 + User root + Port 22143 + + Host laptop + Hostname 192.168.1.9 + User root + Port 22143 + + Host pi + Hostname 192.168.1.6 + User root + Port 22143 + + Host vpn + Hostname 194.113.233.38 + User root + Port 22143 + + Host work + Hostname 192.168.1.5 + User root + Port 22143 + ''; +} diff --git a/module/common/ssh/config b/module/common/ssh/config deleted file mode 100644 index 603d958..0000000 --- a/module/common/ssh/config +++ /dev/null @@ -1,44 +0,0 @@ -Host dasha - HostName 192.168.1.7 - User root - Port 22143 - -Host desktop - Hostname 192.168.1.3 - User root - Port 22143 - -Host fmpmaven - Hostname 10.30.22.10 - User root - Port 22 - -Host fsight - Hostname 10.30.217.25 - User root - Port 22143 - -Host home - HostName 192.168.1.2 - User root - Port 22143 - -Host laptop - Hostname 192.168.1.9 - User root - Port 22143 - -Host pi - Hostname 192.168.1.6 - User root - Port 22143 - -Host vpn - Hostname 194.113.233.38 - User root - Port 22143 - -Host work - Hostname 192.168.1.5 - User root - Port 22143 diff --git a/module/common/tmux/Init.nix b/module/common/tmux/Init.nix new file mode 100644 index 0000000..70b51af --- /dev/null +++ b/module/common/tmux/Init.nix @@ -0,0 +1,268 @@ +{ style, key, util, setting, ... }: let + mod = key.meta.shell.tmux; + + accent = style.color.accent; + bg = style.color.bg.dark; + fg = style.color.fg.light; +in { + config = util.trimTabs '' + # Remap to . + unbind-key C-b + set-option -g prefix C-t + bind-key C-${key.tmux.prefix} send-prefix + + # Disable escape delay. + set -sg escape-time 0 + + # Reload config. + bind -n ${mod}-${key.tmux.reload} source-file /etc/tmux.conf + + # Scroll. + bind -n ${mod}-${key.tmux.scroll.up} copy-mode -u + bind -n ${mod}-${key.tmux.scroll.down} send-keys Pagedown + + # Copy mode. + setw -g mode-keys vi + bind -n ${mod}-${key.tmux.copy.select} copy-mode + bind -n ${mod}-${key.tmux.copy.paste} choose-buffer; + bind -T copy-mode-vi ${key.tmux.copy.select} send -X begin-selection + bind -T copy-mode-vi ${key.tmux.copy.copy} send-keys -X copy-pipe-and-cancel "pbcopy" + + # Remap split keys. + bind -n ${mod}-${key.action.split.vertical} split-window -h -c "#{pane_current_path}" + bind -n ${mod}-${key.action.split.horizontal} split-window -v -c "#{pane_current_path}" + bind -n ${mod}-${key.action.resize.equalize} select-layout tiled + bind -n ${mod}-${key.action.resize.up} resize-pane -U ${setting.tmux.resize.step.vertical} + bind -n ${mod}-${key.action.resize.down} resize-pane -D ${setting.tmux.resize.step.vertical} + bind -n ${mod}-${key.action.resize.left} resize-pane -L ${setting.tmux.resize.step.horizontal} + bind -n ${mod}-${key.action.resize.right} resize-pane -R ${setting.tmux.resize.step.horizontal} + bind -n ${mod}-${key.navigation.move.left} swap-pane -U + bind -n ${mod}-${key.navigation.move.right} swap-pane -D + unbind '"' + unbind % + + # Swith panes. + bind -n ${mod}-${key.navigation.go.left} select-pane -L + bind -n ${mod}-${key.navigation.go.right} select-pane -R + bind -n ${mod}-${key.navigation.go.up} select-pane -U + bind -n ${mod}-${key.navigation.go.down} select-pane -D + + # Close pane. + bind -n ${mod}-${key.action.hide} kill-pane + bind -n ${mod}-${key.action.seek} kill-pane -a + + # Detach. + bind -n ${mod}-${key.action.wait} detach-client + bind -n ${mod}-${key.action.exit} detach-client -a + + # Switch sessions. + bind -n ${mod}-${key.tmux.session.prev} switch-client -p + bind -n ${mod}-${key.tmux.session.next} switch-client -n + bind -n ${mod}-${key.tmux.session.choose} choose-session + + # Resize to smallest client. + set -g window-size smallest + + # Selection style. + set -g mode-style "fg=#${bg} bg=#${accent} bold" + + # Pane style. + set -g pane-border-style "fg=#${bg}" + set -g pane-active-border-style "fg=#${bg}" + + # Statusbar. + bind-key -n ${mod}-${key.tmux.status.toggle} set-option -g status; + bind-key -n ${mod}-${key.tmux.status.uber} run-shell 'tmux_script togglestatusbar' + set -g status-interval ${setting.tmux.status.interval} + set -g status-position bottom + set -g status-justify left + set -g status-style "fg=#${fg}" + + set -g status-left "#[bold] #H-#S #(tmux_script client_count #S)" + set -g status-left-length ${setting.tmux.status.length} + set -g status-right-length ${setting.tmux.status.length} + set -g status-right "#(tmux_script statusbar) %d %a #[bold] %H:%M " + + set-window-option -g window-status-separator "" + + setw -g window-status-current-style "fg=#${accent} bold" + setw -g window-status-current-format " #W " + + setw -g window-status-style "" + setw -g window-status-format " #W " + + set-window-option -g visual-bell off + setw -g window-status-bell-style "bold blink" + + # Create new window. + bind -n ${mod}-${key.tmux.window.new} new-window -c "#{pane_current_path}" + bind -n ${mod}-${key.tmux.window.new_compat} new-window -c "#{pane_current_path}" + + # Close window. + bind -n ${mod}-${key.action.close} kill-window + bind -n ${mod}-${key.action.kill} kill-window -a + + # Switch window. + bind -n ${mod}-${key.navigation.go.next} next-window + bind -n ${mod}-${key.navigation.go.prev} previous-window + + # Move window. + bind -n ${mod}-${key.navigation.move.next} swap-window -t +1\; select-window -t +1 + bind -n ${mod}-${key.navigation.move.prev} swap-window -t -1\; select-window -t -1 + + # Env. + set-option -g default-terminal "tmux-256color" + set-option -g focus-events on + set-option -sa terminal-features "RGB" + set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY BASH_PATH" + ''; + + script = '' + #!/usr/bin/env bash + + function _tmux_battery() { + local IFS=$'\n' + + local batteries=($(ls /sys/class/power_supply/ | grep ^BAT[0-9]$)) + [[ "''${batteries}" = "" ]] && return 1 + + local battery="/sys/class/power_supply/''${batteries[0]}" + local level=$(cat ''${battery}/capacity) + local status=$(cat ''${battery}/status) + local is_charging=false + [[ "''${status}" = "Charging" ]] && is_charging=true + + local icon + if ((level>=${setting.tmux.status.battery.threshold.high})) + then + icon="󱊣" + elif ((level>=${setting.tmux.status.battery.threshold.medium})) + then + icon="󱊢" + elif ((level>=${setting.tmux.status.battery.threshold.low})) + then + icon="󱊡" + else + icon="󰂎" + fi + + echo -n "''${icon}" + ''${is_charging} && echo -n "󱐋" + echo + echo -n "''${level}" + } + + function _tmux_volume() { + local IFS=$'\n' + local level=$(wpctl get-volume @DEFAULT_SINK@ | cut -d\ -f2 | sed -e "s/^0//" -e "s/\.//") + [[ "''${level}" = "" ]] && return 1 + [[ "''${level}" = "00" ]] && level="0" + + local icon + if ((level>=${setting.tmux.status.volume.threshold.high})) + then + icon="󰕾" + elif ((level>=${setting.tmux.status.volume.threshold.medium})) + then + icon="󰖀" + elif ((level>=${setting.tmux.status.volume.threshold.low})) + then + icon="" + else + icon="󰝟" + fi + + local muted=$(wpctl get-volume @DEFAULT_SINK@ | grep '[MUTED]') + if [[ "''${muted}" != "" ]]; then + icon="󰸈" + fi + + echo "''${icon}" + echo -n "''${level}" + } + + function _tmux_statusbar() { + local IFS=$'\n' + local sep="" + local thr_volume=${setting.tmux.status.volume.threshold.show} + local thr_battery=${setting.tmux.status.battery.threshold.show} + local is_uber=$(cat "/tmp/.tmux_uber" || echo -n false) + + # Get data. + battery=($(_tmux_battery)) + volume=($(_tmux_volume)) + + # Prepare separators. + sep_batvol=" " + + if ''${is_uber} || [[ "''${battery[1]}" -lt "''${thr_battery}" ]] || [[ "''${volume[1]}" -gt "''${thr_volume}" ]]; then + sep_batvol=" ''${sep} " + fi + if [[ "''${battery[0]}" = "" ]]; then + sep_batvol="" + fi + + # Print. + echo -n " " + + # Assemble. + if ''${is_uber}; then + local lang=($(_tmux_language)) + [[ "''${lang[0]}" != "" ]] && { + echo -n "''${lang[0]} ''${sep} " + }; + + [[ "''${volume[0]}" != "" ]] && echo -n "''${volume[0]} ''${volume[1]}%''${sep_batvol}" + [[ "''${battery[0]}" != "" ]] && echo -n "''${battery[0]} ''${battery[1]}%" + else + [[ "''${volume[0]}" != "" ]] && { + echo -n "''${volume[0]}" + [[ "''${volume[1]}" -gt 100 ]] && echo -n " ''${volume[1]}%" + echo -n "''${sep_batvol}" + }; + [[ "''${battery[0]}" != "" ]] && { + echo -n "''${battery[0]}" + [[ "''${battery[1]}" -lt 40 ]] && echo -n " ''${battery[1]}%" + }; + fi + + echo -n " " + } + + function _tmux_language() { + local IFS=$'\n' + local lang=$(swaymsg -t get_inputs | jq 'map(select(has("xkb_active_layout_name")))[0].xkb_active_layout_name') + + echo -n ''${lang:1:2} + } + + function _tmux_client_count() { + local IFS=$'\n' + local session=''${1} + local count=$(tmux list-clients -t ''${session} | wc -l) + + [ ''${count} -gt 1 ] && echo -n "+''${count} " + } + + function _tmux_toggle_statusbar() { + local file="/tmp/.tmux_uber" + if [[ ! -f ''${file} ]]; then + echo "true" > ''${file} + elif $(cat ''${file}); then + echo "false" > ''${file} + else + echo "true" > ''${file} + fi + } + + IFS=$'\n' + action=''${1} + session=''${2} + + case "''${action}" in + "statusbar") _tmux_statusbar ;; + "client_count") _tmux_client_count ''${session} ;; + "togglestatusbar") _tmux_toggle_statusbar ;; + esac + ''; +} diff --git a/module/common/tmux/Script.sh b/module/common/tmux/Script.sh deleted file mode 100755 index 58b9596..0000000 --- a/module/common/tmux/Script.sh +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env bash - -function _tmux_battery() { - local IFS=$'\n' - - local batteries=($(ls /sys/class/power_supply/ | grep ^BAT[0-9]$)) - [[ "${batteries}" = "" ]] && return 1 - - local battery="/sys/class/power_supply/${batteries[0]}" - local level=$(cat ${battery}/capacity) - local status=$(cat ${battery}/status) - local is_charging=false - [[ "${status}" = "Charging" ]] && is_charging=true - - local icon - if ((level>=60)) - then - icon="󱊣" - elif ((level>=40)) - then - icon="󱊢" - elif ((level>=20)) - then - icon="󱊡" - else - icon="󰂎" - fi - - echo -n "${icon}" - ${is_charging} && echo -n "󱐋" - echo - echo -n "${level}" -} - -function _tmux_volume() { - local IFS=$'\n' - local level=$(wpctl get-volume @DEFAULT_SINK@ | cut -d\ -f2 | sed -e "s/^0//" -e "s/\.//") - [[ "${level}" = "" ]] && return 1 - [[ "${level}" = "00" ]] && level="0" - - local icon - if ((level>=80)) - then - icon="󰕾" - elif ((level>=40)) - then - icon="󰖀" - elif ((level>=10)) - then - icon="" - else - icon="󰝟" - fi - - local muted=$(wpctl get-volume @DEFAULT_SINK@ | grep '[MUTED]') - if [[ "${muted}" != "" ]]; then - icon="󰸈" - fi - - echo "${icon}" - echo -n "${level}" -} - -function _tmux_statusbar() { - local IFS=$'\n' - local sep="" - local thr_volume=100 - local thr_battery=40 - local is_uber=$(cat "/tmp/.tmux_uber" || echo -n false) - - # Get data. - battery=($(_tmux_battery)) - volume=($(_tmux_volume)) - - # Prepare separators. - sep_batvol=" " - - if ${is_uber} || [[ "${battery[1]}" -lt "${thr_battery}" ]] || [[ "${volume[1]}" -gt "${thr_volume}" ]]; then - sep_batvol=" ${sep} " - fi - if [[ "${battery[0]}" = "" ]]; then - sep_batvol="" - fi - - # Print. - echo -n " " - - # Assemble. - if ${is_uber}; then - local lang=($(_tmux_language)) - [[ "${lang[0]}" != "" ]] && { - echo -n "${lang[0]} ${sep} " - }; - - [[ "${volume[0]}" != "" ]] && echo -n "${volume[0]} ${volume[1]}%${sep_batvol}" - [[ "${battery[0]}" != "" ]] && echo -n "${battery[0]} ${battery[1]}%" - else - [[ "${volume[0]}" != "" ]] && { - echo -n "${volume[0]}" - [[ "${volume[1]}" -gt 100 ]] && echo -n " ${volume[1]}%" - echo -n "${sep_batvol}" - }; - [[ "${battery[0]}" != "" ]] && { - echo -n "${battery[0]}" - [[ "${battery[1]}" -lt 40 ]] && echo -n " ${battery[1]}%" - }; - fi - - echo -n " " -} - -function _tmux_language() { - local IFS=$'\n' - local lang=$(swaymsg -t get_inputs | jq 'map(select(has("xkb_active_layout_name")))[0].xkb_active_layout_name') - - echo -n ${lang:1:2} -} - -function _tmux_client_count() { - local IFS=$'\n' - local session=${1} - local count=$(tmux list-clients -t ${session} | wc -l) - - [ ${count} -gt 1 ] && echo -n "+${count} " -} - -function _tmux_toggle_statusbar() { - local file="/tmp/.tmux_uber" - if [[ ! -f ${file} ]]; then - echo "true" > ${file} - elif $(cat ${file}); then - echo "false" > ${file} - else - echo "true" > ${file} - fi -} - -IFS=$'\n' -action=${1} -session=${2} - -case "${action}" in - "statusbar") _tmux_statusbar ;; - "client_count") _tmux_client_count ${session} ;; - "togglestatusbar") _tmux_toggle_statusbar ;; -esac diff --git a/module/common/tmux/tmux.conf b/module/common/tmux/tmux.conf deleted file mode 100644 index 66eafb1..0000000 --- a/module/common/tmux/tmux.conf +++ /dev/null @@ -1,110 +0,0 @@ -# Remap to . -unbind-key C-b -set-option -g prefix C-t -bind-key C-t send-prefix - -# Disable escape delay. -set -sg escape-time 0 - -# Reload config. -bind -n M-r source-file /etc/tmux.conf - -# Scroll. -bind -n M-p copy-mode -u -bind -n M-n send-keys Pagedown - -# Copy mode. -setw -g mode-keys vi -bind -n M-v copy-mode -bind -n M-P choose-buffer; -bind -T copy-mode-vi v send -X begin-selection -bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" - -# Remap split keys. -bind -n M-\\ split-window -h -c "#{pane_current_path}" -bind -n M-- split-window -v -c "#{pane_current_path}" -bind -n M-= select-layout tiled -bind -n M-k resize-pane -U 1 -bind -n M-j resize-pane -D 1 -bind -n M-h resize-pane -L 1 -bind -n M-l resize-pane -R 1 -bind -n M-A swap-pane -U -bind -n M-D swap-pane -D -unbind '"' -unbind % - -# Swith panes with alt + hjkl. -bind -n M-a select-pane -L -bind -n M-d select-pane -R -bind -n M-w select-pane -U -bind -n M-s select-pane -D - -# Close pane. -bind -n M-c kill-pane -bind -n M-C kill-pane -a - -# Detach. -bind -n M-z detach-client -bind -n M-Z detach-client -a - -# Switch sessions. -bind -n M-9 switch-client -p -bind -n M-0 switch-client -n -bind -n M-g choose-session - -# Resize to smallest client. -set -g window-size smallest - -# Selection style. -set -g mode-style "fg=#$bg bg=#$accent bold" - -# Pane style. -set -g pane-border-style "fg=#$bg" -set -g pane-active-border-style "fg=#$bg" - -# Statusbar. -bind-key -n M-F set-option -g status; -bind-key -n M-f run-shell 'tmux_script togglestatusbar' -set -g status-interval 2 -set -g status-position bottom -set -g status-justify left -set -g status-style "fg=#$fg" - -set -g status-left "#[bold] #H-#S #(tmux_script client_count #S)" -set -g status-left-length 50 -set -g status-right-length 50 -set -g status-right "#(tmux_script statusbar) %d %a #[bold] %H:%M " - -set-window-option -g window-status-separator "" - -setw -g window-status-current-style "fg=#$accent bold" -setw -g window-status-current-format " #W " - -setw -g window-status-style "" -setw -g window-status-format " #W " - -set-window-option -g visual-bell off -setw -g window-status-bell-style "bold blink" - -# Create new window. -bind -n M-Escape new-window -c "#{pane_current_path}" -bind -n M-t new-window -c "#{pane_current_path}" - -# Close window. -bind -n M-x kill-window -bind -n M-X kill-window -a - -# Switch window. -bind -n M-e next-window -bind -n M-q previous-window - -# Move window. -bind -n M-E swap-window -t +1\; select-window -t +1 -bind -n M-Q swap-window -t -1\; select-window -t -1 - -# Env. -set-option -g default-terminal "tmux-256color" -set-option -g focus-events on -set-option -sa terminal-features "RGB" -set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY BASH_PATH" - diff --git a/module/desktop/Dconf.nix b/module/desktop/Dconf.nix index 468d6ec..976529f 100644 --- a/module/desktop/Dconf.nix +++ b/module/desktop/Dconf.nix @@ -1,4 +1,6 @@ -{ lib, ... }: { +{ lib, key, ... }: let + mod = key.meta.window.gnome; +in { programs.dconf.enable = true; programs.dconf.profiles.user = { enableUserDb = true; # Delete `~/.config/dconf/user` to reset user settings. @@ -99,8 +101,8 @@ "org/gnome/desktop/wm/keybindings" = { activate-window-menu = [ "" ]; begin-move = [ "" ]; - begin-resize = [ "r" ]; - close = [ "x" ]; + begin-resize = [ "${mod}${key.action.resize.begin}" ]; + close = [ "${mod}${key.action.close}" ]; cycle-group = [ "" ]; cycle-group-backward = [ "" ]; cycle-panels = [ "" ]; @@ -109,7 +111,7 @@ cycle-windows-backward = [ "" ]; maximize = [ "" ]; maximize-horizontally = [ "" ]; - minimize = [ "s" ]; + minimize = [ "${mod}${key.navigation.go.down}" ]; move-to-monitor-down = [ "" ]; move-to-monitor-left = [ "" ]; move-to-monitor-right = [ "" ]; @@ -119,14 +121,14 @@ move-to-workspace-3 = [ "" ]; move-to-workspace-4 = [ "" ]; move-to-workspace-last = [ "" ]; - move-to-workspace-left = [ "q" ]; - move-to-workspace-right = [ "e" ]; - panel-run-dialog = [ "space" ]; - show-desktop = [ "c" ]; - switch-applications = [ "Tab" ]; - switch-applications-backward = [ "Tab" ]; - switch-group = [ "Tab" ]; - switch-group-backward = [ "Tab" ]; + move-to-workspace-left = [ "${mod}${key.navigation.move.prev}" ]; + move-to-workspace-right = [ "${mod}${key.navigation.move.next}" ]; + panel-run-dialog = [ "${mod}${key.action.launch}" ]; + show-desktop = [ "${mod}${key.action.hide}" ]; + switch-applications = [ "${mod}${key.gnome.window.switch}" ]; + switch-applications-backward = [ "${mod}${key.gnome.window.switch}" ]; + switch-group = [ "${key.gnome.window.switch}" ]; + switch-group-backward = [ "${key.gnome.window.switch}" ]; switch-input-source = [ "" ]; switch-input-source-backward = [ "" ]; switch-panels = [ "" ]; @@ -136,12 +138,12 @@ switch-to-workspace-3 = [ "" ]; switch-to-workspace-4 = [ "" ]; switch-to-workspace-last = [ "" ]; - switch-to-workspace-left = [ "q" ]; - switch-to-workspace-right = [ "e" ]; + switch-to-workspace-left = [ "${mod}${key.navigation.go.prev}" ]; + switch-to-workspace-right = [ "${mod}${key.navigation.go.next}" ]; switch-windows = [ "" ]; switch-windows-backward = [ "" ]; - toggle-fullscreen = [ "f" ]; - toggle-maximized = [ "w" ]; + toggle-fullscreen = [ "${mod}${key.gnome.window.fullscreen}" ]; + toggle-maximized = [ "${mod}${key.navigation.go.up}" ]; unmaximize = [ "" ]; }; @@ -166,8 +168,8 @@ }; "org/gnome/mutter/keybindings" = { - toggle-tiled-left = [ "a" ]; - toggle-tiled-right = [ "d" ]; + toggle-tiled-left = [ "${mod}${key.navigation.go.left}" ]; + toggle-tiled-right = [ "${mod}${key.navigation.go.right}" ]; }; "org/gnome/mutter/wayland/keybindings" = { @@ -212,23 +214,23 @@ magnifier-zoom-in = [ "" ]; magnifier-zoom-out = [ "" ]; screenreader = [ "" ]; - screensaver = [ "z" ]; + screensaver = [ "${mod}${key.action.wait}" ]; }; "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0" = { - binding = "Escape"; + binding = "${mod}${key.gnome.launch.terminal}"; command = "kgx -e bash -c 'tmux new-session -A -s main; bash'"; name = "gnome-terminal"; }; "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1" = { - binding = "z"; + binding = "${mod}${key.action.exit}"; command = "gnome-session-quit --power-off"; name = "gnome-poweroff"; }; "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2" = { - binding = "Escape"; + binding = "${key.gnome.launch.terminal}"; command = "kgx -- btop"; name = "System Monitor"; }; @@ -258,7 +260,7 @@ "org/gnome/shell/keybindings" = { focus-active-notification = [ "" ]; open-application-menu = [ "" ]; - show-screenshot-ui = [ "v" ]; + show-screenshot-ui = [ "${mod}${key.gnome.screenshot}" ]; switch-to-application-1 = [ "" ]; switch-to-application-2 = [ "" ]; switch-to-application-3 = [ "" ]; diff --git a/module/docker/Init.nix b/module/docker/Init.nix new file mode 100644 index 0000000..e18222d --- /dev/null +++ b/module/docker/Init.nix @@ -0,0 +1,7 @@ +{ key, util, ... }: { + text = util.trimTabs '' + { + "detachKeys": "ctrl-${key.action.wait}" + } + ''; +} diff --git a/module/docker/config.json b/module/docker/config.json deleted file mode 100644 index 664f00e..0000000 --- a/module/docker/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "detachKeys": "ctrl-z" -} - diff --git a/module/sway/Init.nix b/module/sway/Init.nix new file mode 100644 index 0000000..90cda95 --- /dev/null +++ b/module/sway/Init.nix @@ -0,0 +1,33 @@ +{ pkgs, wallpaper, style, util, ... } @args: let + mkConfig = { modules }: builtins.foldl' (acc: mod: + acc + (import mod args).text + ) "" modules; + + swayRc = mkConfig { + modules = [ + ./module/Style.nix + ./module/Display.nix + ./module/Input.nix + ./module/Leader.nix + ./module/Font.nix + ./module/Launcher.nix + ./module/Terminal.nix + ./module/TitleBar.nix + ./module/Brightness.nix + ./module/Navigation.nix + ./module/Notification.nix + ./module/Resize.nix + ./module/ScratchPad.nix + ./module/Screenshot.nix + ./module/Sound.nix + ./module/Tiling.nix + ./module/Workspace.nix + ]; + }; +in { + config = util.trimTabs ('' + # Read `man 5 sway` for a complete reference. + include /etc/sway/config.d/* + '' + swayRc); +} + diff --git a/module/sway/module/00-Display b/module/sway/module/00-Display deleted file mode 100644 index 8b34a05..0000000 --- a/module/sway/module/00-Display +++ /dev/null @@ -1,8 +0,0 @@ -# Example configuration: -# -# output HDMI-A-1 resolution 1920x1080 position 1920,0 -# -# You can get the names of your outputs by running: swaymsg -t get_outputs -output * scale 1 -output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" mode 3440x1440@164.999Hz adaptive_sync off pos 0,1080 -output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" transform 180 mode 1920x1080@74.986Hz pos 780,0 diff --git a/module/sway/module/00-Input b/module/sway/module/00-Input deleted file mode 100644 index 70d067e..0000000 --- a/module/sway/module/00-Input +++ /dev/null @@ -1,39 +0,0 @@ -### Input configuration -# -# Example configuration: -# -# input "2:14:SynPS/2_Synaptics_TouchPad" { -# dwt enabled -# tap enabled -# natural_scroll enabled -# middle_emulation enabled -# } -# -# You can get the names of your inputs by running: swaymsg -t get_inputs -# Read `man 5 sway-input` for more information about this section. - -input type:pointer { - accel_profile flat - pointer_accel 0 - dwt enabled - tap enabled - natural_scroll enabled - middle_emulation enabled -} - -input type:touchpad { - accel_profile flat - pointer_accel 0 - dwt enabled - tap enabled - natural_scroll enabled - middle_emulation enabled -} - -input type:keyboard { - xkb_layout us,ru - xkb_options grp:caps_toggle -} - -# Hide mouse cursor after a period of inactivity. -seat seat0 hide_cursor 5000 diff --git a/module/sway/module/00-Leader b/module/sway/module/00-Leader deleted file mode 100644 index beafcc6..0000000 --- a/module/sway/module/00-Leader +++ /dev/null @@ -1,2 +0,0 @@ -# Meta key. Use Mod1 for Alt. -set $mod Mod4 diff --git a/module/sway/module/10-Font b/module/sway/module/10-Font deleted file mode 100644 index 928b258..0000000 --- a/module/sway/module/10-Font +++ /dev/null @@ -1 +0,0 @@ -font "SF Pro Display Medium 0.001" diff --git a/module/sway/module/10-Idle b/module/sway/module/10-Idle deleted file mode 100644 index 4be288a..0000000 --- a/module/sway/module/10-Idle +++ /dev/null @@ -1,12 +0,0 @@ -### Idle configuration -# -# Example configuration: -# -# exec swayidle -w \ -# timeout 300 'swaylock -f -c 000000' \ -# timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ -# before-sleep 'swaylock -f -c 000000' -# -# This will lock your screen after 300 seconds of inactivity, then turn off -# your displays after another 300 seconds, and turn your screens back on when -# resumed. It will also lock your screen before your computer goes to sleep. diff --git a/module/sway/module/10-Launcher b/module/sway/module/10-Launcher deleted file mode 100644 index 5d7faa0..0000000 --- a/module/sway/module/10-Launcher +++ /dev/null @@ -1,6 +0,0 @@ -# Application launcher. -# Note: pass the final command to swaymsg so that the resulting window can be opened -# on the original workspace that the command was run on. -set $menu _dmenu_path_wrapped | wmenu -b -p 'Run:' -i -f "$font_name_popup $font_size_popup" -M $bg -S $bg -N $bg -m $accent -s $accent -n $fg | xargs swaymsg exec -- - -bindsym $mod+space exec $menu diff --git a/module/sway/module/10-StatusBar b/module/sway/module/10-StatusBar deleted file mode 100644 index a62b0e9..0000000 --- a/module/sway/module/10-StatusBar +++ /dev/null @@ -1,14 +0,0 @@ -# Read `man 5 sway-bar` for more information about this section. -# bar { -# position top -# -# # When the status_command prints a new line to stdout, swaybar updates. -# # The default just shows the current date and time. -# status_command while date +'%Y-%m-%d %X'; do sleep 1; done -# -# colors { -# statusline #ffffff -# background #323232 -# inactive_workspace #32323200 #32323200 #5c5c5c -# } -# } diff --git a/module/sway/module/10-Terminal b/module/sway/module/10-Terminal deleted file mode 100644 index 98ed886..0000000 --- a/module/sway/module/10-Terminal +++ /dev/null @@ -1,4 +0,0 @@ -# Terminal emulator. -set $term foot - -bindsym $mod+Escape exec $term -e bash -c "tmux new-session -A -s $USER; bash" diff --git a/module/sway/module/10-TitleBar b/module/sway/module/10-TitleBar deleted file mode 100644 index 57497cf..0000000 --- a/module/sway/module/10-TitleBar +++ /dev/null @@ -1,5 +0,0 @@ -# Disable title bar. -default_border none -default_floating_border none -titlebar_padding 1 -titlebar_border_thickness 0 diff --git a/module/sway/module/20-Brightness b/module/sway/module/20-Brightness deleted file mode 100644 index 1d86f36..0000000 --- a/module/sway/module/20-Brightness +++ /dev/null @@ -1,2 +0,0 @@ -bindsym XF86MonBrightnessDown exec light -U 10 -bindsym XF86MonBrightnessUp exec light -A 10 diff --git a/module/sway/module/20-Navigation b/module/sway/module/20-Navigation deleted file mode 100644 index 475345a..0000000 --- a/module/sway/module/20-Navigation +++ /dev/null @@ -1,20 +0,0 @@ -# Navigation keys. -set $down s -set $left a -set $right d -set $up w - -# Move focus. -bindsym $mod+$down focus down -bindsym $mod+$left focus left -bindsym $mod+$right focus right -bindsym $mod+$up focus up - -# Move the focused window. -bindsym $mod+Shift+$down move down -bindsym $mod+Shift+$left move left -bindsym $mod+Shift+$right move right -bindsym $mod+Shift+$up move up - -# Focus mouse following. -focus_follows_mouse no diff --git a/module/sway/module/20-Notification b/module/sway/module/20-Notification deleted file mode 100644 index 143b167..0000000 --- a/module/sway/module/20-Notification +++ /dev/null @@ -1,5 +0,0 @@ -# Show last notification. -bindsym $mod+n exec makoctl restore - -# Hide all notifications. -bindsym $mod+shift+n exec makoctl dismiss --all diff --git a/module/sway/module/20-Resize b/module/sway/module/20-Resize deleted file mode 100644 index b4e4421..0000000 --- a/module/sway/module/20-Resize +++ /dev/null @@ -1,4 +0,0 @@ -bindsym $mod+j resize grow height 10px -bindsym $mod+h resize shrink width 10px -bindsym $mod+l resize grow width 10px -bindsym $mod+k resize shrink height 10px diff --git a/module/sway/module/20-ScratchPad b/module/sway/module/20-ScratchPad deleted file mode 100644 index 3360989..0000000 --- a/module/sway/module/20-ScratchPad +++ /dev/null @@ -1,38 +0,0 @@ -# Sway has a "scratchpad", which is a bag of holding for windows. -# You can send windows there and get them back later. -# NOTE: Get id with `swaymsg -t get_tree`. - -# Move the currently focused window to the scratchpad -bindsym $mod+shift+c move scratchpad - -# Show the next scratchpad window or hide the focused scratchpad window. -# If there are multiple scratchpad windows, this command cycles through them. -bindsym $mod+c scratchpad show - -# Fix for a goddamn Firefox WebRTC indicator. -for_window [app_id="firefox" title="Firefox — Sharing Indicator"] { - kill -} - -# NetworkManager. -for_window [app_id="nm-connection-editor"] { - move scratchpad - scratchpad show -} - -# Bluetooth. -for_window [app_id=".blueman-manager-wrapped"] { - move scratchpad - scratchpad show -} - -# Sound. -for_window [app_id="pavucontrol"] { - move scratchpad - scratchpad show -} - -# Android emulator controls. -for_window [title="Emulator" window_type="utility"] { - move scratchpad -} diff --git a/module/sway/module/20-Screenshot b/module/sway/module/20-Screenshot deleted file mode 100644 index b70e62b..0000000 --- a/module/sway/module/20-Screenshot +++ /dev/null @@ -1,5 +0,0 @@ -# Fullscreen screenshot. -bindsym $mod+shift+v exec grim -o $(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') - | wl-copy -t image/png - -# Select screenshot. -bindsym $mod+v exec grim -g "$(slurp -d)" - | wl-copy diff --git a/module/sway/module/20-Session b/module/sway/module/20-Session deleted file mode 100644 index 1c180ee..0000000 --- a/module/sway/module/20-Session +++ /dev/null @@ -1,3 +0,0 @@ -# Exit sway (logs you out of your Wayland session). -bindsym $mod+z exec '_twice 1 swaylock -F -c 000000 -k --font "SF Pro Display Medium" --font-size 14' -bindsym $mod+Shift+z exec '_twice 1 systemctl poweroff -i' diff --git a/module/sway/module/20-Sound b/module/sway/module/20-Sound deleted file mode 100644 index 3f3cf21..0000000 --- a/module/sway/module/20-Sound +++ /dev/null @@ -1,3 +0,0 @@ -bindsym XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +10%' -bindsym XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -10%' -bindsym XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle' diff --git a/module/sway/module/20-Tiling b/module/sway/module/20-Tiling deleted file mode 100644 index 2a7ff18..0000000 --- a/module/sway/module/20-Tiling +++ /dev/null @@ -1,37 +0,0 @@ -# Toggle tiling. -bindsym $mod+shift+f floating toggle - -# Swap focus between the tiling area and the floating area -bindsym $mod+r focus mode_toggle - -# Move focus to the parent container -# bindsym $mod+a focus parent - -# Split directions. -bindsym $mod+backslash splith -bindsym $mod+minus splitv - -# Switch the current container between different layout styles. -bindsym $mod+Tab layout toggle split tabbed - -# Fullscreen. -bindsym $mod+f fullscreen - -# Dim inactive windows. -exec $SWAY_IWT_PATH --opacity 0.85 - -# Drag floating windows by holding down $mod and left mouse button. -# Resize them with right mouse button + $mod. -# Despite the name, also works for non-floating windows. -# Change normal to inverse to use left mouse button for resizing and right -# mouse button for dragging. -floating_modifier $mod normal - -# Kill focused window. -bindsym $mod+x kill - -# Add gaps. -gaps inner 10 - -# Launch everything tiled. -# for_window [all] floating disable diff --git a/module/sway/module/20-Workspace b/module/sway/module/20-Workspace deleted file mode 100644 index a23d28e..0000000 --- a/module/sway/module/20-Workspace +++ /dev/null @@ -1,33 +0,0 @@ -# Switch to workspace. -bindsym $mod+1 workspace number 1 -bindsym $mod+2 workspace number 2 -bindsym $mod+3 workspace number 3 -bindsym $mod+4 workspace number 4 -bindsym $mod+5 workspace number 5 -bindsym $mod+6 workspace number 6 -bindsym $mod+7 workspace number 7 -bindsym $mod+8 workspace number 8 -bindsym $mod+9 workspace number 9 -bindsym $mod+0 workspace number 10 - -# Move focused container to workspace. -bindsym $mod+Shift+1 move container to workspace number 1 -bindsym $mod+Shift+2 move container to workspace number 2 -bindsym $mod+Shift+3 move container to workspace number 3 -bindsym $mod+Shift+4 move container to workspace number 4 -bindsym $mod+Shift+5 move container to workspace number 5 -bindsym $mod+Shift+6 move container to workspace number 6 -bindsym $mod+Shift+7 move container to workspace number 7 -bindsym $mod+Shift+8 move container to workspace number 8 -bindsym $mod+Shift+9 move container to workspace number 9 -bindsym $mod+Shift+0 move container to workspace number 10 -# Note: workspaces can have any name you want, not just numbers. -# We just use 1-10 as the default. - -# Switch left-right. -bindsym $mod+e workspace next -bindsym $mod+q workspace prev - -# Move left-right. -bindsym $mod+Shift+e move container to workspace next -bindsym $mod+Shift+q move container to workspace prev diff --git a/module/sway/module/Brightness.nix b/module/sway/module/Brightness.nix new file mode 100644 index 0000000..994afb2 --- /dev/null +++ b/module/sway/module/Brightness.nix @@ -0,0 +1,8 @@ +{ setting, ... }: let + step = setting.brightness.step; +in { + text = '' + bindsym XF86MonBrightnessDown exec light -U ${step} + bindsym XF86MonBrightnessUp exec light -A ${step} + ''; +} diff --git a/module/sway/module/Display.nix b/module/sway/module/Display.nix new file mode 100644 index 0000000..aab7583 --- /dev/null +++ b/module/sway/module/Display.nix @@ -0,0 +1,12 @@ +{ ... }: { + text = '' + # Example configuration: + # + # output HDMI-A-1 resolution 1920x1080 position 1920,0 + # + # You can get the names of your outputs by running: swaymsg -t get_outputs + output * scale 1 + output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" mode 3440x1440@164.999Hz adaptive_sync off pos 0,1080 + output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" transform 180 mode 1920x1080@74.986Hz pos 780,0 + ''; +} diff --git a/module/sway/module/Font.nix b/module/sway/module/Font.nix new file mode 100644 index 0000000..ae01b7b --- /dev/null +++ b/module/sway/module/Font.nix @@ -0,0 +1,5 @@ +{ ... }: { + text = '' + font "SF Pro Display Medium 0.001" + ''; +} diff --git a/module/sway/module/Input.nix b/module/sway/module/Input.nix new file mode 100644 index 0000000..f658c66 --- /dev/null +++ b/module/sway/module/Input.nix @@ -0,0 +1,43 @@ +{ ... }: { + text = '' + ### Input configuration + # + # Example configuration: + # + # input "2:14:SynPS/2_Synaptics_TouchPad" { + # dwt enabled + # tap enabled + # natural_scroll enabled + # middle_emulation enabled + # } + # + # You can get the names of your inputs by running: swaymsg -t get_inputs + # Read `man 5 sway-input` for more information about this section. + + input type:pointer { + accel_profile flat + pointer_accel 0 + dwt enabled + tap enabled + natural_scroll enabled + middle_emulation enabled + } + + input type:touchpad { + accel_profile flat + pointer_accel 0 + dwt enabled + tap enabled + natural_scroll enabled + middle_emulation enabled + } + + input type:keyboard { + xkb_layout us,ru + xkb_options grp:caps_toggle + } + + # Hide mouse cursor after a period of inactivity. + seat seat0 hide_cursor 5000 + ''; +} diff --git a/module/sway/module/Launcher.nix b/module/sway/module/Launcher.nix new file mode 100644 index 0000000..1956d04 --- /dev/null +++ b/module/sway/module/Launcher.nix @@ -0,0 +1,17 @@ +{ style, key, ... }: let + fontName = style.font.serif.name; + fontSize = toString(style.font.size.popup); + + accent = style.color.accent; + bg = style.color.bg.dark; + fg = style.color.fg.light; +in { + text = '' + # Application launcher. + # Note: pass the final command to swaymsg so that the resulting window can be opened + # on the original workspace that the command was run on. + set $menu _dmenu_path_wrapped | wmenu -b -p 'Run:' -i -f "${fontName} ${fontSize}" -M ${bg} -S ${bg} -N ${bg} -m ${accent} -s ${accent} -n ${fg} | xargs swaymsg exec -- + + bindsym $mod+${key.action.launch} exec $menu + ''; +} diff --git a/module/sway/module/Leader.nix b/module/sway/module/Leader.nix new file mode 100644 index 0000000..d50e3c6 --- /dev/null +++ b/module/sway/module/Leader.nix @@ -0,0 +1,6 @@ +{ key, ... }: { + text = '' + # Meta key. Use Mod1 for Alt. + set $mod ${key.meta.window.sway} + ''; +} diff --git a/module/sway/module/Navigation.nix b/module/sway/module/Navigation.nix new file mode 100644 index 0000000..e687201 --- /dev/null +++ b/module/sway/module/Navigation.nix @@ -0,0 +1,24 @@ +{ key, ... }: { + text = '' + # Navigation keys. + set $down ${key.navigation.go.down} + set $left ${key.navigation.go.left} + set $right ${key.navigation.go.right} + set $up ${key.navigation.go.up} + + # Move focus. + bindsym $mod+$down focus down + bindsym $mod+$left focus left + bindsym $mod+$right focus right + bindsym $mod+$up focus up + + # Move the focused window. + bindsym $mod+Shift+$down move down + bindsym $mod+Shift+$left move left + bindsym $mod+Shift+$right move right + bindsym $mod+Shift+$up move up + + # Focus mouse following. + focus_follows_mouse no + ''; +} diff --git a/module/sway/module/Notification.nix b/module/sway/module/Notification.nix new file mode 100644 index 0000000..0a322d8 --- /dev/null +++ b/module/sway/module/Notification.nix @@ -0,0 +1,9 @@ +{ key, ... }: { + text = '' + # Show last notification. + bindsym $mod+${key.sway.notification.restore} exec makoctl restore + + # Hide all notifications. + bindsym $mod+${key.sway.notification.dismiss} exec makoctl dismiss --all + ''; +} diff --git a/module/sway/module/Resize.nix b/module/sway/module/Resize.nix new file mode 100644 index 0000000..37960e2 --- /dev/null +++ b/module/sway/module/Resize.nix @@ -0,0 +1,8 @@ +{ key, setting, ... }: { + text = '' + bindsym $mod+${key.action.resize.down} resize grow height ${setting.sway.resize.step.vertical} + bindsym $mod+${key.action.resize.up} resize shrink height ${setting.sway.resize.step.vertical} + bindsym $mod+${key.action.resize.left} resize shrink width ${setting.sway.resize.step.horizontal} + bindsym $mod+${key.action.resize.right} resize grow width ${setting.sway.resize.step.horizontal} + ''; +} diff --git a/module/sway/module/ScratchPad.nix b/module/sway/module/ScratchPad.nix new file mode 100644 index 0000000..8f8feab --- /dev/null +++ b/module/sway/module/ScratchPad.nix @@ -0,0 +1,42 @@ +{ key, ... }: { + text = '' + # Sway has a "scratchpad", which is a bag of holding for windows. + # You can send windows there and get them back later. + # NOTE: Get id with `swaymsg -t get_tree`. + + # Move the currently focused window to the scratchpad + bindsym $mod+shift+${key.action.seek} move scratchpad + + # Show the next scratchpad window or hide the focused scratchpad window. + # If there are multiple scratchpad windows, this command cycles through them. + bindsym $mod+${key.action.hide} scratchpad show + + # Fix for a goddamn Firefox WebRTC indicator. + for_window [app_id="firefox" title="Firefox — Sharing Indicator"] { + kill + } + + # NetworkManager. + for_window [app_id="nm-connection-editor"] { + move scratchpad + scratchpad show + } + + # Bluetooth. + for_window [app_id=".blueman-manager-wrapped"] { + move scratchpad + scratchpad show + } + + # Sound. + for_window [app_id="pavucontrol"] { + move scratchpad + scratchpad show + } + + # Android emulator controls. + for_window [title="Emulator" window_type="utility"] { + move scratchpad + } + ''; +} diff --git a/module/sway/module/Screenshot.nix b/module/sway/module/Screenshot.nix new file mode 100644 index 0000000..05eefcb --- /dev/null +++ b/module/sway/module/Screenshot.nix @@ -0,0 +1,9 @@ +{ key, ... }: { + text = '' + # Fullscreen screenshot. + bindsym $mod+${key.sway.screenshot.screen} exec grim -o $(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') - | wl-copy -t image/png + + # Select screenshot. + bindsym $mod+${key.sway.screenshot.selection} exec grim -g "$(slurp -d)" - | wl-copy + ''; +} diff --git a/module/sway/module/Sound.nix b/module/sway/module/Sound.nix new file mode 100644 index 0000000..d275ffb --- /dev/null +++ b/module/sway/module/Sound.nix @@ -0,0 +1,9 @@ +{ setting, ... }: let + step = setting.volume.step; +in { + text = '' + bindsym XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +${step}%' + bindsym XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -${step}%' + bindsym XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle' + ''; +} diff --git a/module/sway/Config.nix b/module/sway/module/Style.nix similarity index 63% rename from module/sway/Config.nix rename to module/sway/module/Style.nix index 5f8ad74..8fa9cfe 100644 --- a/module/sway/Config.nix +++ b/module/sway/module/Style.nix @@ -1,23 +1,17 @@ -{ pkgs, wallpaper, style, ... }: let +{ wallpaper, style, ... }: let accent = style.color.accent; - bg = style.color.bg_dark; - bg_alt = style.color.bg; - fg = style.color.fg; - fg_alt = style.color.fg_dark; + bg = style.color.bg.dark; + bg_alt = style.color.bg.regular; + fg = style.color.fg.light; + fg_alt = style.color.fg.regular; negative = style.color.negative; in { - config = pkgs.writeText "sway_config" '' - # Read `man 5 sway` for a complete reference. - + text = '' output * bg ${wallpaper.path} fill client.focused #${accent} #${accent} #${fg} #${accent} #${accent} client.focused_inactive #${bg_alt} #${bg_alt} #${fg} #${bg_alt} #${bg_alt} client.unfocused #${bg_alt} #${bg_alt} #${fg_alt} #${bg_alt} #${bg_alt} client.urgent #${bg_alt} #${negative} #${fg_alt} #${negative} #${negative} client.placeholder #${bg} #${bg} #${fg} #${bg} #${bg} - - include /etc/sway/config.d/* - include $SWAY_CONFIG/* ''; } - diff --git a/module/sway/module/Terminal.nix b/module/sway/module/Terminal.nix new file mode 100644 index 0000000..9898e20 --- /dev/null +++ b/module/sway/module/Terminal.nix @@ -0,0 +1,8 @@ +{ key, ... }: { + text = '' + # Terminal emulator. + set $term foot + + bindsym $mod+${key.sway.launch.terminal} exec $term -e bash -c "tmux new-session -A -s $USER; bash" + ''; +} diff --git a/module/sway/module/Tiling.nix b/module/sway/module/Tiling.nix new file mode 100644 index 0000000..4cf5d96 --- /dev/null +++ b/module/sway/module/Tiling.nix @@ -0,0 +1,41 @@ +{ key, setting, ... }: { + text = '' + # Toggle tiling. + bindsym $mod+${key.sway.window.floating.toggle} floating toggle + + # Swap focus between the tiling area and the floating area + bindsym $mod+${key.sway.window.floating.cycle} focus mode_toggle + + # Move focus to the parent container + # bindsym $mod+a focus parent + + # Split directions. + bindsym $mod+${key.sway.window.split.horizontal} splith + bindsym $mod+${key.sway.window.split.vertical} splitv + + # Switch the current container between different layout styles. + bindsym $mod+${key.sway.window.layout.toggle} layout toggle split tabbed + + # Fullscreen. + bindsym $mod+${key.sway.window.fullscreen} fullscreen + + # Dim inactive windows. + exec $SWAY_IWT_PATH --opacity ${setting.sway.window.opacity.inactive} + + # Drag floating windows by holding down $mod and left mouse button. + # Resize them with right mouse button + $mod. + # Despite the name, also works for non-floating windows. + # Change normal to inverse to use left mouse button for resizing and right + # mouse button for dragging. + floating_modifier $mod normal + + # Kill focused window. + bindsym $mod+${key.action.close} kill + + # Add gaps. + gaps inner ${setting.sway.window.gap} + + # Launch everything tiled. + # for_window [all] floating disable + ''; +} diff --git a/module/sway/module/TitleBar.nix b/module/sway/module/TitleBar.nix new file mode 100644 index 0000000..6cb1d96 --- /dev/null +++ b/module/sway/module/TitleBar.nix @@ -0,0 +1,9 @@ +{ ... }: { + text = '' + # Disable title bar. + default_border none + default_floating_border none + titlebar_padding 1 + titlebar_border_thickness 0 + ''; +} diff --git a/module/sway/module/Workspace.nix b/module/sway/module/Workspace.nix new file mode 100644 index 0000000..0de4218 --- /dev/null +++ b/module/sway/module/Workspace.nix @@ -0,0 +1,37 @@ +{ key, ... }: { + text = '' + # Switch to workspace. + bindsym $mod+1 workspace number 1 + bindsym $mod+2 workspace number 2 + bindsym $mod+3 workspace number 3 + bindsym $mod+4 workspace number 4 + bindsym $mod+5 workspace number 5 + bindsym $mod+6 workspace number 6 + bindsym $mod+7 workspace number 7 + bindsym $mod+8 workspace number 8 + bindsym $mod+9 workspace number 9 + bindsym $mod+0 workspace number 10 + + # Move focused container to workspace. + bindsym $mod+Shift+1 move container to workspace number 1 + bindsym $mod+Shift+2 move container to workspace number 2 + bindsym $mod+Shift+3 move container to workspace number 3 + bindsym $mod+Shift+4 move container to workspace number 4 + bindsym $mod+Shift+5 move container to workspace number 5 + bindsym $mod+Shift+6 move container to workspace number 6 + bindsym $mod+Shift+7 move container to workspace number 7 + bindsym $mod+Shift+8 move container to workspace number 8 + bindsym $mod+Shift+9 move container to workspace number 9 + bindsym $mod+Shift+0 move container to workspace number 10 + # Note: workspaces can have any name you want, not just numbers. + # We just use 1-10 as the default. + + # Switch left-right. + bindsym $mod+${key.navigation.go.next} workspace next + bindsym $mod+${key.navigation.go.prev} workspace prev + + # Move left-right. + bindsym $mod+Shift+${key.navigation.move.next} move container to workspace next + bindsym $mod+Shift+${key.navigation.move.prev} move container to workspace prev + ''; +} diff --git a/part/Key.nix b/part/Key.nix new file mode 100644 index 0000000..6b63100 --- /dev/null +++ b/part/Key.nix @@ -0,0 +1,145 @@ +{ ... }: { + meta = { + app.nvim = " "; + shell.tmux = "M"; + window = { + sway = "Mod4"; + gnome = ""; + }; + }; + + navigation = { + go = { + down = "s"; + left = "a"; + right = "d"; + up = "w"; + next = "e"; + prev = "q"; + }; + move = { + down = "S"; + left = "A"; + right = "D"; + up = "W"; + next = "E"; + prev = "Q"; + }; + }; + + action = { + resize = { + down = "j"; + left = "h"; + right = "l"; + up = "k"; + begin = "r"; + equalize = "="; + }; + split = { + horizontal = "-"; + vertical = "\\\\"; + }; + close = "x"; + kill = "X"; + hide = "c"; + seek = "C"; + wait = "z"; + exit = "Z"; + launch = "Space"; + repeat = "."; + }; + + nvim = { + buffer.new = "n"; + colorscheme.toggle = { + contrast = "["; + light = "]"; + }; + editor = { + indent.size = ""; + git.inspect = "g"; + }; + telescope = { + mod = "f"; + all = "a"; + buffer = "b"; + file = "f"; + grep = "g"; + help = "h"; + treesitter = "t"; + }; + text = { + comment = "/"; + prompt = "p"; + sort = "A"; + }; + window = { + filetree = "1"; + trouble = "2"; + todo = "3"; + terminal = "4"; + whichkey = "?"; + }; + }; + + tmux = { + prefix = "t"; + reload = "r"; + scroll = { + down = "n"; + up = "p"; + }; + copy = { + copy = "y"; + paste = "P"; + select = "v"; + }; + session = { + choose = "g"; + next = "0"; + prev = "9"; + }; + status = { + toggle = "F"; + uber = "f"; + }; + window = { + new = "Escape"; + new_compat = "t"; + }; + }; + + sway = { + notification = { + dismiss = "shift+N"; + restore = "n"; + }; + screenshot = { + selection = "v"; + screen = "shift+V"; + }; + launch.terminal = "Escape"; + window = { + floating = { + toggle = "shift+f"; + cycle = "r"; + }; + split = { + horizontal = "backslash"; + vertical = "minus"; + }; + layout.toggle = "Tab"; + fullscreen = "f"; + }; + }; + + gnome = { + window = { + switch = "Tab"; + fullscreen = "f"; + }; + launch.terminal = "Escape"; + screenshot = "v"; + }; +} diff --git a/part/Setting.nix b/part/Setting.nix new file mode 100644 index 0000000..9937569 --- /dev/null +++ b/part/Setting.nix @@ -0,0 +1,58 @@ +{ ... }: { + tmux = { + resize.step = { + vertical = "1"; + horizontal = "1"; + }; + status = { + interval = "2"; + length = "50"; + battery.threshold = { + high = "60"; + medium = "40"; + low = "20"; + show = "40"; + }; + volume.threshold = { + high = "80"; + medium = "40"; + low = "10"; + show = "100"; + }; + }; + }; + + nvim = { + editor = { + relativenumber = "true"; + indent.default = "2"; + }; + resize.step = { + vertical = "2"; + horizontal = "4"; + }; + }; + + sway = { + resize.step = { + vertical = "10px"; + horizontal = "10px"; + }; + window = { + gap = "10"; + opacity.inactive = "0.85"; + }; + }; + + foot = { + font = { + step = "1"; + dpi = "yes"; + }; + }; + + top.refresh = "2000"; + + brightness.step = "10"; + volume.step = "10"; +} diff --git a/part/Style.nix b/part/Style.nix index 47f1bfc..8593467 100644 --- a/part/Style.nix +++ b/part/Style.nix @@ -1,12 +1,16 @@ { config, ... }: { color = { + bg = { + regular = config.lib.stylix.colors.base01; + dark = config.lib.stylix.colors.base00; + light = config.lib.stylix.colors.base07; + }; + fg = { + regular = config.lib.stylix.colors.base05; + dark = config.lib.stylix.colors.base04; + light = config.lib.stylix.colors.base06; + }; accent = config.lib.stylix.colors.base0A; - bg = config.lib.stylix.colors.base01; - bg_dark = config.lib.stylix.colors.base00; - bg_light = config.lib.stylix.colors.base07; - fg = config.lib.stylix.colors.base05; - fg_dark = config.lib.stylix.colors.base04; - fg_light = config.lib.stylix.colors.base06; heading = config.lib.stylix.colors.base0D; hl = config.lib.stylix.colors.base03; keyword = config.lib.stylix.colors.base0E; diff --git a/part/Util.nix b/part/Util.nix new file mode 100644 index 0000000..38d2976 --- /dev/null +++ b/part/Util.nix @@ -0,0 +1,12 @@ +{ pkgs, ... }: { + # Remove tabs indentation, + trimTabs = text: let + shouldStripTab = lines: builtins.all (line: (line == "") || (pkgs.lib.strings.hasPrefix " " line)) lines; + stripTab = lines: builtins.map (line: pkgs.lib.strings.removePrefix " " line) lines; + stripTabs = lines: if (shouldStripTab lines) then (stripTabs (stripTab lines)) else lines; + in + builtins.concatStringsSep "\n" (stripTabs (pkgs.lib.strings.splitString "\n" text)); + + # List all files in a dir. + ls = path: map (f: "${path}/${f}") (builtins.attrNames (builtins.readDir path)); +} diff --git a/part/style/Gruvbox.nix b/part/style/Gruvbox.nix index 4f51fb0..15ddfea 100644 --- a/part/style/Gruvbox.nix +++ b/part/style/Gruvbox.nix @@ -34,7 +34,7 @@ fonts = { monospace.name = "Terminess Nerd Font Mono"; emoji.name = "Noto Color Emoji"; - serif.name = "SF Pro Display"; + serif.name = "SF Pro Display"; sansSerif.name = "SF Pro Display"; sizes = { applications = 12; diff --git a/user/home/Dasha.nix b/user/home/Dasha.nix index 25c8e7b..64a8c72 100644 --- a/user/home/Dasha.nix +++ b/user/home/Dasha.nix @@ -1,12 +1,14 @@ -{ const, color, style, pkgs, ... }: { +{ const, username, homeDir, util, style, pkgs, setting, key, ... }: { imports = [ (import ./Default.nix { - color = color; - const = const; - homeDir = "/home/dasha"; - pkgs = pkgs; - style = style; username = "dasha"; + homeDir = "/home/dasha"; + const = const; + key = key; + pkgs = pkgs; + setting = setting; + style = style; + util = util; }) ]; } diff --git a/user/home/Default.nix b/user/home/Default.nix index afe57e9..31e2396 100644 --- a/user/home/Default.nix +++ b/user/home/Default.nix @@ -1,6 +1,9 @@ -{ const, username, homeDir, style, pkgs, ... }: let - footConfig = import ./module/foot/Foot.nix { style = style; }; - makoConfig = import ./module/mako/Mako.nix { style = style; }; +{ const, username, homeDir, util, style, pkgs, setting, key, ... } @args: let + foot = import ./module/foot/Init.nix args; + mako = import ./module/mako/Init.nix args; + editorconfig = import ./module/editorconfig/Init.nix args; + btop = import ./module/top/btop/Init.nix args; + htop = import ./module/top/htop/Init.nix args; in { home-manager.backupFileExtension = "old"; @@ -11,13 +14,13 @@ in { home.stateVersion = const.stateVersion; home.file = { - ".config/btop".source = ./module/top/btop; - ".config/htop".source = ./module/top/htop; - ".config/mako/config".text = makoConfig.config; - ".config/foot/foot.ini".text = footConfig.config; - ".editorconfig".source = ./module/Editorconfig; - ".parallel/will-cite".text = ""; - "media/template".source = ./module/template; + ".config/btop/btop.conf".text = btop.config; + ".config/htop/htoprc".text = htop.config; + ".config/mako/config".text = mako.config; + ".config/foot/foot.ini".text = foot.config; + ".editorconfig".text = editorconfig.config; + ".parallel/will-cite".text = ""; + "media/template".source = ./module/template; }; # Directories. diff --git a/user/home/Root.nix b/user/home/Root.nix index 24820a3..84cbf36 100644 --- a/user/home/Root.nix +++ b/user/home/Root.nix @@ -1,12 +1,14 @@ -{ const, color, pkgs, style, ... }: { +{ const, username, homeDir, util, style, pkgs, setting, key, ... }: { imports = [ (import ./Default.nix { - color = color; - const = const; - homeDir = "/root"; - pkgs = pkgs; - style = style; username = "root"; + homeDir = "/root"; + const = const; + key = key; + pkgs = pkgs; + setting = setting; + style = style; + util = util; }) ]; } diff --git a/user/home/Voronind.nix b/user/home/Voronind.nix index 47be605..fb59d1d 100644 --- a/user/home/Voronind.nix +++ b/user/home/Voronind.nix @@ -1,12 +1,14 @@ -{ const, color, pkgs, style, ... }: { +{ const, username, homeDir, util, style, pkgs, setting, key, ... }: { imports = [ (import ./Default.nix { - color = color; - const = const; - homeDir = "/home/voronind"; - pkgs = pkgs; - style = style; username = "voronind"; + homeDir = "/home/voronind"; + const = const; + key = key; + pkgs = pkgs; + setting = setting; + style = style; + util = util; }) ]; } diff --git a/user/home/module/Editorconfig b/user/home/module/Editorconfig deleted file mode 100644 index ca4266c..0000000 --- a/user/home/module/Editorconfig +++ /dev/null @@ -1,21 +0,0 @@ -root = true - -[*] -end_of_line = lf -charset = utf-8 -indent_style = tab -indent_size = 2 -insert_final_newline = true -trim_trailing_whitespace = true - -[Makefile] -indent_size = 2 - -[*.{nix,js}] -indent_size = 2 - -[*.{lua,kt,kts,rs,py}] -indent_size = 4 - -[*.{sh,md}] -indent_size = 8 diff --git a/user/home/module/editorconfig/Init.nix b/user/home/module/editorconfig/Init.nix new file mode 100644 index 0000000..6d1207b --- /dev/null +++ b/user/home/module/editorconfig/Init.nix @@ -0,0 +1,25 @@ +{ util, ... }: { + config = util.trimTabs '' + root = true + + [*] + end_of_line = lf + charset = utf-8 + indent_style = tab + indent_size = 2 + insert_final_newline = true + trim_trailing_whitespace = true + + [Makefile] + indent_size = 2 + + [*.{nix,js}] + indent_size = 2 + + [*.{lua,kt,kts,rs,py}] + indent_size = 4 + + [*.{sh,md}] + indent_size = 8 + ''; +} diff --git a/user/home/module/foot/Foot.nix b/user/home/module/foot/Init.nix similarity index 64% rename from user/home/module/foot/Foot.nix rename to user/home/module/foot/Init.nix index 70bd971..8ad8c46 100644 --- a/user/home/module/foot/Foot.nix +++ b/user/home/module/foot/Init.nix @@ -1,15 +1,15 @@ -{ style, ... }: { - config = '' +{ style, setting, util, ... }: { + config = util.trimTabs '' font=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} # font-bold=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} font-italic=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} font-bold-italic=${style.font.monospace.name}:size=${toString(style.font.size.terminal)} - dpi-aware=yes - font-size-adjustment=1 + dpi-aware=${setting.foot.font.dpi} + font-size-adjustment=${setting.foot.font.step} [colors] alpha=${toString(style.opacity.terminal)} - background=${style.color.bg_dark} - foreground=${style.color.fg_light} + background=${style.color.bg.dark} + foreground=${style.color.fg.light} ''; } diff --git a/user/home/module/mako/Init.nix b/user/home/module/mako/Init.nix new file mode 100644 index 0000000..6961669 --- /dev/null +++ b/user/home/module/mako/Init.nix @@ -0,0 +1,14 @@ +{ style, util, ... }: { + config = util.trimTabs '' + anchor=top-center + default-timeout=5000 + font=${style.font.serif.name} ${toString(style.font.size.popup)} + background-color=#${style.color.bg.regular} + border-color=#${style.color.bg.regular} + text-color=#${style.color.fg.light} + height=120 + icons=0 + margin=32 + width=480 + ''; +} diff --git a/user/home/module/mako/Mako.nix b/user/home/module/mako/Mako.nix deleted file mode 100644 index e17b210..0000000 --- a/user/home/module/mako/Mako.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ style, ... }: { - config = ''anchor=top-center -default-timeout=5000 -font=${style.font.serif.name} ${toString(style.font.size.popup)} -background-color=#${style.color.bg} -border-color=#${style.color.bg} -text-color=#${style.color.fg} -height=120 -icons=0 -margin=32 -width=480''; -} diff --git a/user/home/module/top/btop/Init.nix b/user/home/module/top/btop/Init.nix new file mode 100644 index 0000000..f89d561 --- /dev/null +++ b/user/home/module/top/btop/Init.nix @@ -0,0 +1,249 @@ +{ setting, util, ... }: { + config = util.trimTabs '' + #? Config file for btop v. 1.3.0 + + #* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. + #* Themes should be placed in "../share/btop/themes" relative to binary or "$HOME/.config/btop/themes" + color_theme = "/usr/share/btop/themes/gruvbox_material_dark.theme" + + #* If the theme set background should be shown, set to False if you want terminal background transparency. + theme_background = False + + #* Sets if 24-bit truecolor should be used, will convert 24-bit colors to 256 color (6x6x6 color cube) if false. + truecolor = True + + #* Set to true to force tty mode regardless if a real tty has been detected or not. + #* Will force 16-color mode and TTY theme, set all graph symbols to "tty" and swap out other non tty friendly symbols. + force_tty = False + + #* Define presets for the layout of the boxes. Preset 0 is always all boxes shown with default settings. Max 9 presets. + #* Format: "box_name:P:G,box_name:P:G" P=(0 or 1) for alternate positions, G=graph symbol to use for box. + #* Use whitespace " " as separator between different presets. + #* Example: "cpu:0:default,mem:0:tty,proc:1:default cpu:0:braille,proc:0:tty" + presets = "" + + #* Set to True to enable "h,j,k,l,g,G" keys for directional control in lists. + #* Conflicting keys for h:"help" and k:"kill" is accessible while holding shift. + vim_keys = True + + #* Rounded corners on boxes, is ignored if TTY mode is ON. + rounded_corners = True + + #* Default symbols to use for graph creation, "braille", "block" or "tty". + #* "braille" offers the highest resolution but might not be included in all fonts. + #* "block" has half the resolution of braille but uses more common characters. + #* "tty" uses only 3 different symbols but will work with most fonts and should work in a real TTY. + #* Note that "tty" only has half the horizontal resolution of the other two, so will show a shorter historical view. + graph_symbol = "braille" + + # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". + graph_symbol_cpu = "default" + + # Graph symbol to use for graphs in gpu box, "default", "braille", "block" or "tty". + graph_symbol_gpu = "default" + + # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". + graph_symbol_mem = "default" + + # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". + graph_symbol_net = "default" + + # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". + graph_symbol_proc = "default" + + #* Manually set which boxes to show. Available values are "cpu mem net proc" and "gpu0" through "gpu5", separate values with whitespace. + shown_boxes = "cpu mem net proc" + + #* Update time in milliseconds, recommended 2000 ms or above for better sample times for graphs. + update_ms = ${setting.top.refresh} + + #* Processes sorting, "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu direct", + #* "cpu lazy" sorts top process over time (easier to follow), "cpu direct" updates top process directly. + proc_sorting = "memory" + + #* Reverse sorting order, True or False. + proc_reversed = False + + #* Show processes as a tree. + proc_tree = False + + #* Use the cpu graph colors in the process list. + proc_colors = True + + #* Use a darkening gradient in the process list. + proc_gradient = True + + #* If process cpu usage should be of the core it's running on or usage of the total available cpu power. + proc_per_core = False + + #* Show process memory as bytes instead of percent. + proc_mem_bytes = True + + #* Show cpu graph for each process. + proc_cpu_graphs = True + + #* Use /proc/[pid]/smaps for memory information in the process info box (very slow but more accurate) + proc_info_smaps = False + + #* Show proc box on left side of screen instead of right. + proc_left = True + + #* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop). + proc_filter_kernel = True + + #* In tree-view, always accumulate child process resources in the parent process. + proc_aggregate = False + + #* Sets the CPU stat shown in upper half of the CPU graph, "total" is always available. + #* Select from a list of detected attributes from the options menu. + cpu_graph_upper = "total" + + #* Sets the CPU stat shown in lower half of the CPU graph, "total" is always available. + #* Select from a list of detected attributes from the options menu. + cpu_graph_lower = "total" + + #* If gpu info should be shown in the cpu box. Available values = "Auto", "On" and "Off". + show_gpu_info = "Auto" + + #* Toggles if the lower CPU graph should be inverted. + cpu_invert_lower = True + + #* Set to True to completely disable the lower CPU graph. + cpu_single_graph = False + + #* Show cpu box at bottom of screen instead of top. + cpu_bottom = False + + #* Shows the system uptime in the CPU box. + show_uptime = True + + #* Show cpu temperature. + check_temp = True + + #* Which sensor to use for cpu temperature, use options menu to select from list of available sensors. + cpu_sensor = "Auto" + + #* Show temperatures for cpu cores also if check_temp is True and sensors has been found. + show_coretemp = True + + #* Set a custom mapping between core and coretemp, can be needed on certain cpus to get correct temperature for correct core. + #* Use lm-sensors or similar to see which cores are reporting temperatures on your machine. + #* Format "x:y" x=core with wrong temp, y=core with correct temp, use space as separator between multiple entries. + #* Example: "4:0 5:1 6:3" + cpu_core_map = "" + + #* Which temperature scale to use, available values: "celsius", "fahrenheit", "kelvin" and "rankine". + temp_scale = "celsius" + + #* Use base 10 for bits/bytes sizes, KB = 1000 instead of KiB = 1024. + base_10_sizes = True + + #* Show CPU frequency. + show_cpu_freq = True + + #* Draw a clock at top of screen, formatting according to strftime, empty string to disable. + #* Special formatting: /host = hostname | /user = username | /uptime = system uptime + clock_format = "%X" + + #* Update main ui in background when menus are showing, set this to false if the menus is flickering too much for comfort. + background_update = True + + #* Custom cpu model name, empty string to disable. + custom_cpu_name = "" + + #* Optional filter for shown disks, should be full path of a mountpoint, separate multiple values with whitespace " ". + #* Begin line with "exclude=" to change to exclude filter, otherwise defaults to "most include" filter. Example: disks_filter="exclude=/boot /home/user". + disks_filter = "exclude=/boot /boot/efi" + + #* Show graphs instead of meters for memory values. + mem_graphs = True + + #* Show mem box below net box instead of above. + mem_below_net = False + + #* Count ZFS ARC in cached and available memory. + zfs_arc_cached = True + + #* If swap memory should be shown in memory box. + show_swap = True + + #* Show swap as a disk, ignores show_swap value above, inserts itself after first disk. + swap_disk = False + + #* If mem box should be split to also show disks info. + show_disks = True + + #* Filter out non physical disks. Set this to False to include network disks, RAM disks and similar. + only_physical = True + + #* Read disks list from /etc/fstab. This also disables only_physical. + use_fstab = True + + #* Setting this to True will hide all datasets, and only show ZFS pools. (IO stats will be calculated per-pool) + zfs_hide_datasets = False + + #* Set to true to show available disk space for privileged users. + disk_free_priv = False + + #* Toggles if io activity % (disk busy time) should be shown in regular disk usage view. + show_io_stat = True + + #* Toggles io mode for disks, showing big graphs for disk read/write speeds. + io_mode = False + + #* Set to True to show combined read/write io graphs in io mode. + io_graph_combined = False + + #* Set the top speed for the io graphs in MiB/s (100 by default), use format "mountpoint:speed" separate disks with whitespace " ". + #* Example: "/mnt/media:100 /:20 /boot:1". + io_graph_speeds = "" + + #* Set fixed values for network graphs in Mebibits. Is only used if net_auto is also set to False. + net_download = 100 + + net_upload = 100 + + #* Use network graphs auto rescaling mode, ignores any values set above and rescales down to 10 Kibibytes at the lowest. + net_auto = True + + #* Sync the auto scaling for download and upload to whichever currently has the highest scale. + net_sync = True + + #* Starts with the Network Interface specified here. + net_iface = "" + + #* Show battery stats in top right if battery is present. + show_battery = True + + #* Which battery to use if multiple are present. "Auto" for auto detection. + selected_battery = "Auto" + + #* Set loglevel for "~/.config/btop/btop.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". + #* The level set includes all lower levels, i.e. "DEBUG" will show all logging info. + log_level = "WARNING" + + #* Measure PCIe throughput on NVIDIA cards, may impact performance on certain cards. + nvml_measure_pcie_speeds = True + + #* Horizontally mirror the GPU graph. + gpu_mirror_graph = True + + #* Custom gpu0 model name, empty string to disable. + custom_gpu_name0 = "" + + #* Custom gpu1 model name, empty string to disable. + custom_gpu_name1 = "" + + #* Custom gpu2 model name, empty string to disable. + custom_gpu_name2 = "" + + #* Custom gpu3 model name, empty string to disable. + custom_gpu_name3 = "" + + #* Custom gpu4 model name, empty string to disable. + custom_gpu_name4 = "" + + #* Custom gpu5 model name, empty string to disable. + custom_gpu_name5 = "" + ''; +} diff --git a/user/home/module/top/btop/btop.conf b/user/home/module/top/btop/btop.conf deleted file mode 100644 index 82b7280..0000000 --- a/user/home/module/top/btop/btop.conf +++ /dev/null @@ -1,245 +0,0 @@ -#? Config file for btop v. 1.3.0 - -#* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. -#* Themes should be placed in "../share/btop/themes" relative to binary or "$HOME/.config/btop/themes" -color_theme = "/usr/share/btop/themes/gruvbox_material_dark.theme" - -#* If the theme set background should be shown, set to False if you want terminal background transparency. -theme_background = False - -#* Sets if 24-bit truecolor should be used, will convert 24-bit colors to 256 color (6x6x6 color cube) if false. -truecolor = True - -#* Set to true to force tty mode regardless if a real tty has been detected or not. -#* Will force 16-color mode and TTY theme, set all graph symbols to "tty" and swap out other non tty friendly symbols. -force_tty = False - -#* Define presets for the layout of the boxes. Preset 0 is always all boxes shown with default settings. Max 9 presets. -#* Format: "box_name:P:G,box_name:P:G" P=(0 or 1) for alternate positions, G=graph symbol to use for box. -#* Use whitespace " " as separator between different presets. -#* Example: "cpu:0:default,mem:0:tty,proc:1:default cpu:0:braille,proc:0:tty" -presets = "" - -#* Set to True to enable "h,j,k,l,g,G" keys for directional control in lists. -#* Conflicting keys for h:"help" and k:"kill" is accessible while holding shift. -vim_keys = True - -#* Rounded corners on boxes, is ignored if TTY mode is ON. -rounded_corners = True - -#* Default symbols to use for graph creation, "braille", "block" or "tty". -#* "braille" offers the highest resolution but might not be included in all fonts. -#* "block" has half the resolution of braille but uses more common characters. -#* "tty" uses only 3 different symbols but will work with most fonts and should work in a real TTY. -#* Note that "tty" only has half the horizontal resolution of the other two, so will show a shorter historical view. -graph_symbol = "braille" - -# Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". -graph_symbol_cpu = "default" - -# Graph symbol to use for graphs in gpu box, "default", "braille", "block" or "tty". -graph_symbol_gpu = "default" - -# Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". -graph_symbol_mem = "default" - -# Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". -graph_symbol_net = "default" - -# Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". -graph_symbol_proc = "default" - -#* Manually set which boxes to show. Available values are "cpu mem net proc" and "gpu0" through "gpu5", separate values with whitespace. -shown_boxes = "cpu mem net proc" - -#* Update time in milliseconds, recommended 2000 ms or above for better sample times for graphs. -update_ms = 2000 - -#* Processes sorting, "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu direct", -#* "cpu lazy" sorts top process over time (easier to follow), "cpu direct" updates top process directly. -proc_sorting = "memory" - -#* Reverse sorting order, True or False. -proc_reversed = False - -#* Show processes as a tree. -proc_tree = False - -#* Use the cpu graph colors in the process list. -proc_colors = True - -#* Use a darkening gradient in the process list. -proc_gradient = True - -#* If process cpu usage should be of the core it's running on or usage of the total available cpu power. -proc_per_core = False - -#* Show process memory as bytes instead of percent. -proc_mem_bytes = True - -#* Show cpu graph for each process. -proc_cpu_graphs = True - -#* Use /proc/[pid]/smaps for memory information in the process info box (very slow but more accurate) -proc_info_smaps = False - -#* Show proc box on left side of screen instead of right. -proc_left = True - -#* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop). -proc_filter_kernel = True - -#* In tree-view, always accumulate child process resources in the parent process. -proc_aggregate = False - -#* Sets the CPU stat shown in upper half of the CPU graph, "total" is always available. -#* Select from a list of detected attributes from the options menu. -cpu_graph_upper = "total" - -#* Sets the CPU stat shown in lower half of the CPU graph, "total" is always available. -#* Select from a list of detected attributes from the options menu. -cpu_graph_lower = "total" - -#* If gpu info should be shown in the cpu box. Available values = "Auto", "On" and "Off". -show_gpu_info = "Auto" - -#* Toggles if the lower CPU graph should be inverted. -cpu_invert_lower = True - -#* Set to True to completely disable the lower CPU graph. -cpu_single_graph = False - -#* Show cpu box at bottom of screen instead of top. -cpu_bottom = False - -#* Shows the system uptime in the CPU box. -show_uptime = True - -#* Show cpu temperature. -check_temp = True - -#* Which sensor to use for cpu temperature, use options menu to select from list of available sensors. -cpu_sensor = "Auto" - -#* Show temperatures for cpu cores also if check_temp is True and sensors has been found. -show_coretemp = True - -#* Set a custom mapping between core and coretemp, can be needed on certain cpus to get correct temperature for correct core. -#* Use lm-sensors or similar to see which cores are reporting temperatures on your machine. -#* Format "x:y" x=core with wrong temp, y=core with correct temp, use space as separator between multiple entries. -#* Example: "4:0 5:1 6:3" -cpu_core_map = "" - -#* Which temperature scale to use, available values: "celsius", "fahrenheit", "kelvin" and "rankine". -temp_scale = "celsius" - -#* Use base 10 for bits/bytes sizes, KB = 1000 instead of KiB = 1024. -base_10_sizes = True - -#* Show CPU frequency. -show_cpu_freq = True - -#* Draw a clock at top of screen, formatting according to strftime, empty string to disable. -#* Special formatting: /host = hostname | /user = username | /uptime = system uptime -clock_format = "%X" - -#* Update main ui in background when menus are showing, set this to false if the menus is flickering too much for comfort. -background_update = True - -#* Custom cpu model name, empty string to disable. -custom_cpu_name = "" - -#* Optional filter for shown disks, should be full path of a mountpoint, separate multiple values with whitespace " ". -#* Begin line with "exclude=" to change to exclude filter, otherwise defaults to "most include" filter. Example: disks_filter="exclude=/boot /home/user". -disks_filter = "exclude=/boot /boot/efi" - -#* Show graphs instead of meters for memory values. -mem_graphs = True - -#* Show mem box below net box instead of above. -mem_below_net = False - -#* Count ZFS ARC in cached and available memory. -zfs_arc_cached = True - -#* If swap memory should be shown in memory box. -show_swap = True - -#* Show swap as a disk, ignores show_swap value above, inserts itself after first disk. -swap_disk = False - -#* If mem box should be split to also show disks info. -show_disks = True - -#* Filter out non physical disks. Set this to False to include network disks, RAM disks and similar. -only_physical = True - -#* Read disks list from /etc/fstab. This also disables only_physical. -use_fstab = True - -#* Setting this to True will hide all datasets, and only show ZFS pools. (IO stats will be calculated per-pool) -zfs_hide_datasets = False - -#* Set to true to show available disk space for privileged users. -disk_free_priv = False - -#* Toggles if io activity % (disk busy time) should be shown in regular disk usage view. -show_io_stat = True - -#* Toggles io mode for disks, showing big graphs for disk read/write speeds. -io_mode = False - -#* Set to True to show combined read/write io graphs in io mode. -io_graph_combined = False - -#* Set the top speed for the io graphs in MiB/s (100 by default), use format "mountpoint:speed" separate disks with whitespace " ". -#* Example: "/mnt/media:100 /:20 /boot:1". -io_graph_speeds = "" - -#* Set fixed values for network graphs in Mebibits. Is only used if net_auto is also set to False. -net_download = 100 - -net_upload = 100 - -#* Use network graphs auto rescaling mode, ignores any values set above and rescales down to 10 Kibibytes at the lowest. -net_auto = True - -#* Sync the auto scaling for download and upload to whichever currently has the highest scale. -net_sync = True - -#* Starts with the Network Interface specified here. -net_iface = "" - -#* Show battery stats in top right if battery is present. -show_battery = True - -#* Which battery to use if multiple are present. "Auto" for auto detection. -selected_battery = "Auto" - -#* Set loglevel for "~/.config/btop/btop.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". -#* The level set includes all lower levels, i.e. "DEBUG" will show all logging info. -log_level = "WARNING" - -#* Measure PCIe throughput on NVIDIA cards, may impact performance on certain cards. -nvml_measure_pcie_speeds = True - -#* Horizontally mirror the GPU graph. -gpu_mirror_graph = True - -#* Custom gpu0 model name, empty string to disable. -custom_gpu_name0 = "" - -#* Custom gpu1 model name, empty string to disable. -custom_gpu_name1 = "" - -#* Custom gpu2 model name, empty string to disable. -custom_gpu_name2 = "" - -#* Custom gpu3 model name, empty string to disable. -custom_gpu_name3 = "" - -#* Custom gpu4 model name, empty string to disable. -custom_gpu_name4 = "" - -#* Custom gpu5 model name, empty string to disable. -custom_gpu_name5 = "" diff --git a/user/home/module/top/htop/Init.nix b/user/home/module/top/htop/Init.nix new file mode 100644 index 0000000..da987b9 --- /dev/null +++ b/user/home/module/top/htop/Init.nix @@ -0,0 +1,67 @@ +{ util, ... }: { + config = util.trimTabs '' + # Beware! This file is rewritten by htop when settings are changed in the interface. + # The parser is also very primitive, and not human-friendly. + htop_version=3.2.2 + config_reader_min_version=3 + fields=0 48 17 18 38 39 40 2 46 47 49 1 + hide_kernel_threads=1 + hide_userland_threads=1 + hide_running_in_container=0 + shadow_other_users=0 + show_thread_names=0 + show_program_path=1 + highlight_base_name=0 + highlight_deleted_exe=1 + shadow_distribution_path_prefix=0 + highlight_megabytes=1 + highlight_threads=1 + highlight_changes=0 + highlight_changes_delay_secs=5 + find_comm_in_cmdline=1 + strip_exe_from_cmdline=1 + show_merged_command=0 + header_margin=1 + screen_tabs=0 + detailed_cpu_time=0 + cpu_count_from_one=0 + show_cpu_usage=1 + show_cpu_frequency=1 + show_cpu_temperature=1 + degree_fahrenheit=0 + update_process_names=0 + account_guest_in_cpu_meter=0 + color_scheme=0 + enable_mouse=1 + delay=15 + hide_function_bar=0 + header_layout=two_50_50 + column_meters_0=LeftCPUs2 Memory Swap + column_meter_modes_0=1 1 1 + column_meters_1=RightCPUs2 DateTime Tasks LoadAverage DiskIO NetworkIO Uptime + column_meter_modes_1=1 2 2 2 2 2 2 + tree_view=0 + sort_key=46 + tree_sort_key=0 + sort_direction=-1 + tree_sort_direction=1 + tree_view_always_by_pid=0 + all_branches_collapsed=0 + screen:Main=PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command + .sort_key=PERCENT_CPU + .tree_sort_key=PID + .tree_view=0 + .tree_view_always_by_pid=0 + .sort_direction=-1 + .tree_sort_direction=1 + .all_branches_collapsed=0 + screen:I/O=PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE + .sort_key=IO_RATE + .tree_sort_key=PID + .tree_view=0 + .tree_view_always_by_pid=0 + .sort_direction=-1 + .tree_sort_direction=1 + .all_branches_collapsed=0 + ''; +} diff --git a/user/home/module/top/htop/htoprc b/user/home/module/top/htop/htoprc deleted file mode 100644 index aa1891b..0000000 --- a/user/home/module/top/htop/htoprc +++ /dev/null @@ -1,63 +0,0 @@ -# Beware! This file is rewritten by htop when settings are changed in the interface. -# The parser is also very primitive, and not human-friendly. -htop_version=3.2.2 -config_reader_min_version=3 -fields=0 48 17 18 38 39 40 2 46 47 49 1 -hide_kernel_threads=1 -hide_userland_threads=1 -hide_running_in_container=0 -shadow_other_users=0 -show_thread_names=0 -show_program_path=1 -highlight_base_name=0 -highlight_deleted_exe=1 -shadow_distribution_path_prefix=0 -highlight_megabytes=1 -highlight_threads=1 -highlight_changes=0 -highlight_changes_delay_secs=5 -find_comm_in_cmdline=1 -strip_exe_from_cmdline=1 -show_merged_command=0 -header_margin=1 -screen_tabs=0 -detailed_cpu_time=0 -cpu_count_from_one=0 -show_cpu_usage=1 -show_cpu_frequency=1 -show_cpu_temperature=1 -degree_fahrenheit=0 -update_process_names=0 -account_guest_in_cpu_meter=0 -color_scheme=0 -enable_mouse=1 -delay=15 -hide_function_bar=0 -header_layout=two_50_50 -column_meters_0=LeftCPUs2 Memory Swap -column_meter_modes_0=1 1 1 -column_meters_1=RightCPUs2 DateTime Tasks LoadAverage DiskIO NetworkIO Uptime -column_meter_modes_1=1 2 2 2 2 2 2 -tree_view=0 -sort_key=46 -tree_sort_key=0 -sort_direction=-1 -tree_sort_direction=1 -tree_view_always_by_pid=0 -all_branches_collapsed=0 -screen:Main=PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command -.sort_key=PERCENT_CPU -.tree_sort_key=PID -.tree_view=0 -.tree_view_always_by_pid=0 -.sort_direction=-1 -.tree_sort_direction=1 -.all_branches_collapsed=0 -screen:I/O=PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE -.sort_key=IO_RATE -.tree_sort_key=PID -.tree_view=0 -.tree_view_always_by_pid=0 -.sort_direction=-1 -.tree_sort_direction=1 -.all_branches_collapsed=0