Skip to content

Commit

Permalink
home-manager/zsh: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Nov 8, 2023
1 parent 8bf9d0f commit 28ad4a3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 44 deletions.
17 changes: 0 additions & 17 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@
url = "github:zsh-users/zsh-completions";
flake = false;
};
zsh-history-substring-search = {
url = "github:zsh-users/zsh-history-substring-search";
flake = false;
};
zsh-syntax-highlighting = {
url = "github:zsh-users/zsh-syntax-highlighting";
flake = false;
Expand Down
53 changes: 30 additions & 23 deletions home-manager/cli/zsh.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
{ config, pkgs, lib, flake, ... }:

let
get-ip = pkgs.writeShellScriptBin "get-ip" ''
${lib.getExe pkgs.curl} -Ss "https://ifconfig.me"
'';
get-ip' = pkgs.writeShellScriptBin "get-ip!" ''
${lib.getExe pkgs.curl} -Ss "https://ipapi.co/$(${lib.getExe get-ip})/yaml"
'';
remove-symlink = pkgs.writeShellScriptBin "remove-symlink" ''
[[ -L "$1" ]] && \
${lib.getExe' pkgs.coreutils "cp"} --remove-destination \
"$(${lib.getExe' pkgs.coreutils "readlink"} "$1")" "$1"
'';
in
{
options.home-manager.cli.zsh.enable = lib.mkEnableOption "ZSH config" // {
default = config.home-manager.cli.enable;
};

config = lib.mkIf config.home-manager.cli.zsh.enable {
home.packages = with pkgs; lib.optionals (!stdenv.isDarwin) [
home.packages = with pkgs; [
get-ip
get-ip'
remove-symlink
] ++ lib.optionals (!stdenv.isDarwin) [
(run-bg-alias "open" "${xdg-utils}/bin/xdg-open")
];

Expand All @@ -23,6 +41,12 @@
share = true;
};

historySubstringSearch = {
enable = true;
searchUpKey = [ "$terminfo[kcuu1]" ];
searchDownKey = [ "$terminfo[kcud1]" ];
};

sessionVariables = {
# Enable scroll support
LESS = "--RAW-CONTROL-CHARS";
Expand Down Expand Up @@ -57,21 +81,9 @@
zstyle ':zim:ssh' ids /dev/null
'';

initExtra = with pkgs; ''
# helpers
run-bg() {
(
exec 0>&-
exec 1>&-
exec 2>&-
"$@"
) &!
}
get-ip() { ${curl}/bin/curl -Ss "https://ifconfig.me" }
get-ip!() { ${curl}/bin/curl -Ss "https://ipapi.co/$(get-ip)/yaml" }
remove-symlink() {
[[ -L "$1" ]] && cp --remove-destination "$(readlink "$1")" "$1"
}
initExtra = /* bash */ ''
# avoid duplicated entries in PATH
typeset -U PATH
# try to correct the spelling of commands
setopt correct
Expand All @@ -84,8 +96,8 @@
bindkey -M vicmd v edit-command-line
# zsh-history-substring-search
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
# historySubstringSearch.{searchUpKey,searchDownKey} does not work with
# vicmd, this is why we have this here
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down
Expand All @@ -96,9 +108,6 @@
for file in "$HOME/.zshrc.d/"*.zsh; do
[[ -f "$file" ]] && source "$file"
done
# avoid duplicated entries in PATH
typeset -U PATH
'';

plugins =
Expand Down Expand Up @@ -132,8 +141,6 @@
(zshPlugin "zsh-autopair")
(zshPlugin "zsh-completions")
(zshPlugin "zsh-syntax-highlighting")
# Should be the last one
(zshPlugin "zsh-history-substring-search")
];
};

Expand Down

0 comments on commit 28ad4a3

Please sign in to comment.