Skip to content

Commit

Permalink
Add lf (#3)
Browse files Browse the repository at this point in the history
* Add lf

* cleanup

* cleanup
  • Loading branch information
vaporif authored Nov 25, 2024
1 parent 52f0e10 commit aa22a19
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
13 changes: 13 additions & 0 deletions flake.lock

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

11 changes: 9 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};

lfcd-sh = {
url = "https://raw.githubusercontent.com/gokcehan/lf/master/etc/lfcd.sh";
flake = false;
};

fzf-git-sh = {
url = "https://raw.githubusercontent.com/junegunn/fzf-git.sh/main/fzf-git.sh";
flake = false;
};
};

outputs = { nixpkgs, home-manager, fzf-git-sh, ... }:
outputs = { nixpkgs, home-manager, fzf-git-sh, lfcd-sh, ... }:
let
system = "aarch64-darwin";
pkgs = import nixpkgs { inherit system; };
fzf-git-sh-package = pkgs.writeShellScriptBin "fzf-git.sh" (builtins.readFile fzf-git-sh);
lfcd-sh-package = pkgs.writeShellScriptBin "lfcd.sh" (builtins.readFile lfcd-sh);
in
{
homeConfigurations.vaporif =
Expand Down Expand Up @@ -45,7 +52,7 @@
}
];
extraSpecialArgs = {
inherit fzf-git-sh-package;
inherit fzf-git-sh-package lfcd-sh-package;
};
};
};
Expand Down
20 changes: 19 additions & 1 deletion home.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, fzf-git-sh-package, ... }: {
{ pkgs, fzf-git-sh-package, lfcd-sh-package, ... }: {
programs.home-manager.enable = true;

home.packages = with pkgs; [
Expand Down Expand Up @@ -32,13 +32,30 @@
gh.enable = true;
bat.enable = true;
lazygit.enable = true;
lf = {
enable = true;

keybindings = {
"." = "set hidden!";
e = "$$EDITOR $f";
"f" = null;
br = "cd ~/Repos/";
be = "cd ~/Repos/eiger/";
bm = "cd ~/.config/home-manager/";
};

# NOTE: escaping scripts is not cool so just readFile
extraConfig = builtins.readFile ./lf.config;
};

zsh = {
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
shellAliases = {
t = "lfcd";
lf = "lfcd";
lg = "lazygit";
ls = "eza -a";
cat = "bat";
Expand All @@ -51,6 +68,7 @@
initExtra = ''
${builtins.readFile ./.zshrc}
source ${fzf-git-sh-package}/bin/fzf-git.sh
source ${lfcd-sh-package}/bin/lfcd.sh
'';
};

Expand Down
27 changes: 27 additions & 0 deletions lf.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmd fzf_jump ${{
res="$(find . -maxdepth 1 | fzf --reverse --header="Jump to location")"
if [ -n "$res" ]; then
if [ -d "$res" ]; then
cmd="cd"
else
cmd="select"
fi
res="$(printf '%s' "$res" | sed 's/\\/\\\\/g;s/"/\\"/g')"
lf -remote "send $id $cmd \"$res\""
fi
}}
map ff :fzf_jump

cmd fzf_search ${{
cmd="rg --column --line-number --no-heading --color=always --smart-case"
fzf --ansi --disabled --layout=reverse --header="Search in files" --delimiter=: \
--bind="start:reload([ -n {q} ] && $cmd -- {q} || true)" \
--bind="change:reload([ -n {q} ] && $cmd -- {q} || true)" \
--bind='enter:become(lf -remote "send $id select \"$(printf "%s" {1} | sed '\''s/\\/\\\\/g;s/"/\\"/g'\'')\"")' \
--preview='cat -- {1}' # Use your favorite previewer here (bat, source-highlight, etc.), for example:
#--preview-window='+{2}-/2' \
#--preview='bat --color=always --highlight-line={2} -- {1}'
# Alternatively you can even use the same previewer you've configured for lf
#--preview='~/.config/lf/cleaner; ~/.config/lf/previewer {1} "$FZF_PREVIEW_COLUMNS" "$FZF_PREVIEW_LINES" "$FZF_PREVIEW_LEFT" "$FZF_PREVIEW_TOP"'
}}
map fg :fzf_search

0 comments on commit aa22a19

Please sign in to comment.