move nixos and darwin back into modules dir

This commit is contained in:
Noah Masur
2023-02-20 20:37:37 -05:00
parent ded498f4c9
commit cc84f1d37a
163 changed files with 30 additions and 30 deletions

View File

@ -0,0 +1,131 @@
{ config, pkgs, lib, ... }: {
users.users.${config.user}.shell = pkgs.fish;
programs.fish.enable =
true; # Needed for LightDM to remember username (TODO: fix)
home-manager.users.${config.user} = {
# Packages used in abbreviations and aliases
home.packages = with pkgs; [ curl exa ];
programs.fish = {
enable = true;
shellAliases = { ls = "exa"; };
functions = {
commandline-git-commits = {
description = "Insert commit into commandline";
body = builtins.readFile ./functions/commandline-git-commits.fish;
};
copy = {
description = "Copy file contents into clipboard";
body = "cat $argv | pbcopy"; # Need to fix for non-macOS
};
edit = {
description = "Open a file in Vim";
body = builtins.readFile ./functions/edit.fish;
};
envs = {
description = "Evaluate a bash-like environment variables file";
body = ''set -gx (cat $argv | tr "=" " " | string split ' ')'';
};
fcd = {
description = "Jump to directory";
argumentNames = "directory";
body = builtins.readFile ./functions/fcd.fish;
};
fish_user_key_bindings = {
body = builtins.readFile ./functions/fish_user_key_bindings.fish;
};
ip = { body = builtins.readFile ./functions/ip.fish; };
json = {
description = "Tidy up JSON using jq";
body = "pbpaste | jq '.' | pbcopy"; # Need to fix for non-macOS
};
note = {
description = "Edit or create a note";
argumentNames = "filename";
body = builtins.readFile ./functions/note.fish;
};
recent = {
description = "Open a recent file in Vim";
body = builtins.readFile ./functions/recent.fish;
};
search-and-edit = {
description = "Search and open the relevant file in Vim";
body = builtins.readFile ./functions/search-and-edit.fish;
};
syncnotes = {
description = "Full git commit on notes";
body = builtins.readFile ./functions/syncnotes.fish;
};
};
interactiveShellInit = ''
fish_vi_key_bindings
bind yy fish_clipboard_copy
bind Y fish_clipboard_copy
bind -M visual y fish_clipboard_copy
bind -M default p fish_clipboard_paste
set -g fish_vi_force_cursor
set -g fish_cursor_default block
set -g fish_cursor_insert line
set -g fish_cursor_visual block
set -g fish_cursor_replace_one underscore
'';
loginShellInit = "";
shellAliases = { };
shellAbbrs = {
# Directory aliases
l = "ls -lh";
lh = "ls -lh";
ll = "ls -alhF";
la = "ls -a";
c = "cd";
"-" = "cd -";
mkd = "mkdir -pv";
# System
s = "sudo";
sc = "systemctl";
scs = "systemctl status";
m = "make";
# Vim (overwritten by Neovim)
v = "vim";
vl = "vim -c 'normal! `0'";
# Notes
sn = "syncnotes";
# Fun CLI Tools
weather = "curl wttr.in/$WEATHER_CITY";
moon = "curl wttr.in/Moon";
# Cheat Sheets
ssl =
"openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out server.csr";
fingerprint = "ssh-keyscan myhost.com | ssh-keygen -lf -";
publickey = "ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub";
forloop = "for i in (seq 1 100)";
# Docker
dc = "$DOTS/bin/docker_cleanup";
dr = "docker run --rm -it";
db = "docker build . -t";
# Rust
ca = "cargo";
};
shellInit = "";
};
home.sessionVariables.fish_greeting = "";
programs.starship.enableFishIntegration = true;
programs.zoxide.enableFishIntegration = true;
programs.fzf.enableFishIntegration = true;
};
}

View File

@ -0,0 +1,6 @@
set commit (git-commits)
if [ $commit ]
commandline -i "$commit"
else
commandline -i HEAD
end

View File

@ -0,0 +1,4 @@
set vimfile (fzf)
and set vimfile (echo $vimfile | tr -d '\r')
and commandline -r "vim $vimfile"
and commandline -f execute

View File

@ -0,0 +1,10 @@
if test -z $directory
set directory "$HOME"
end
if ! test -d $directory
echo "Directory not found: $directory"
return 1
end
set jump (fd -t d . $directory | fzf)
and cd $jump $argv
and commandline -f execute

View File

@ -0,0 +1,20 @@
bind -M insert \co edit
bind -M default \co edit
bind -M insert \cs search-and-edit
bind -M default \cs search-and-edit
bind -M insert \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute'
bind -M default \ca 'cd ~; and edit; and commandline -a "; cd -"; commandline -f execute'
bind -M insert \ce recent
bind -M default \ce recent
bind -M default \cg commandline-git-commits
bind -M insert \cg 'commandline -i (git rev-parse --show-toplevel 2>/dev/null || echo ".")'
bind -M insert \cf fcd
bind -M default \cf fcd
bind -M insert \cp projects
bind -M default \cp projects
bind -M insert \x1F accept-autosuggestion
bind -M default \x1F accept-autosuggestion
bind -M insert \cn 'commandline -r "nix run nixpkgs#"'
bind -M default \cn 'commandline -r "nix run nixpkgs#"'
bind -M insert \x11F nix-fzf
bind -M default \x11F nix-fzf

View File

@ -0,0 +1,122 @@
#!/usr/local/bin/fish
function fish_vi_cursor -d 'Set cursor shape for different vi modes'
# If we're not interactive, there is effectively no bind mode.
if not status is-interactive
return
end
# This is hard to test in expect, since the exact sequences depend on the environment.
# Instead disable it.
if set -q FISH_UNIT_TESTS_RUNNING
return
end
# If this variable is set, skip all checks
if not set -q fish_vi_force_cursor
# Emacs Makes All Cursors Suck
if set -q INSIDE_EMACS
return
end
# vte-based terms set $TERM = xterm*, but only gained support in 2015.
# From https://bugzilla.gnome.org/show_bug.cgi?id=720821, it appears it was version 0.40.0
if set -q VTE_VERSION
and test "$VTE_VERSION" -lt 4000 2>/dev/null
return
end
# Similarly, genuine XTerm can do it since v280.
if set -q XTERM_VERSION
and not test (string replace -r "XTerm\((\d+)\)" '$1' -- "$XTERM_VERSION") -ge 280 2>/dev/null
return
end
# We need one of these terms.
# It would be lovely if we could rely on terminfo, but:
# - The "Ss" entry isn't a thing in macOS' old and crusty terminfo
# - It is set for xterm, and everyone and their dog claims to be xterm
#
# So we just don't care about $TERM, unless it is one of the few terminals that actually have their own entry.
#
# Note: Previous versions also checked $TMUX, and made sure that then $TERM was screen* or tmux*.
# We don't care, since we *cannot* handle term-in-a-terms 100% correctly.
if not set -q KONSOLE_PROFILE_NAME
and not test -n "$KONSOLE_VERSION" -a "$KONSOLE_VERSION" -ge 200400 # konsole, but new.
and not set -q ITERM_PROFILE
and not set -q VTE_VERSION # which version is already checked above
and not set -q WT_PROFILE_ID
and not set -q XTERM_VERSION
and not string match -rq '^st(-.*)$' -- $TERM
and not string match -q 'xterm-kitty*' -- $TERM
and not string match -q 'rxvt*' -- $TERM
and not string match -q 'alacritty*' -- $TERM
return
end
# HACK: Explicitly disable on ITERM because of #3696, which is weirdness with multi-line prompts.
# --force-iterm is now deprecated; set $fish_vi_force_cursor instead
if contains -- $argv[1] --force-iterm
set -e argv[1]
else if set -q ITERM_PROFILE
return
end
end
set -l terminal $argv[1]
set -q terminal[1]
or set terminal auto
set -l function
switch "$terminal"
case auto
# Nowadays, konsole does not set $KONSOLE_PROFILE_NAME anymore,
# and it uses the xterm sequences.
if set -q KONSOLE_PROFILE_NAME
set function __fish_cursor_konsole
else if set -q ITERM_PROFILE
set function __fish_cursor_1337
else
set function __fish_cursor_xterm
end
case konsole
set function __fish_cursor_konsole
case xterm
set function __fish_cursor_xterm
end
set -l tmux_prefix
set -l tmux_postfix
if set -q TMUX
set tmux_prefix echo -ne "'\ePtmux;\e'"
set tmux_postfix echo -ne "'\e\\\\'"
end
set -q fish_cursor_unknown
or set -g fish_cursor_unknown block blink
echo "
function fish_vi_cursor_handle --on-variable fish_bind_mode --on-event fish_postexec --on-event fish_focus_in
set -l varname fish_cursor_\$fish_bind_mode
if not set -q \$varname
set varname fish_cursor_unknown
end
$tmux_prefix
$function \$\$varname
$tmux_postfix
end
" | source
echo "
function fish_vi_cursor_handle_preexec --on-event fish_preexec
set -l varname fish_cursor_default
if not set -q \$varname
set varname fish_cursor_unknown
end
$tmux_prefix
$function \$\$varname
$tmux_postfix
end
" | source
end

View File

@ -0,0 +1,14 @@
set gitfile (git status -s \
| fzf \
--height 50% \
-m \
--preview-window right:70% \
--layout reverse \
--preview 'set -l IFS; set gd (git diff --color=always (echo {} | awk \'{$1=$1};1\' | cut -d" " -f2)); if test "$gd"; echo "$gd"; else; bat --color=always (echo {} | awk \'{$1=$1};1\' | cut -d" " -f2); end')
and for gf in $gitfile
set gf (echo $gf \
| awk '{$1=$1};1' \
| cut -d' ' -f2 \
)
and git add $gf
end

View File

@ -0,0 +1,8 @@
set commitline (git log \
--pretty="format:%C(auto)%ar %h%d %s" \
| fzf \
--height 50% \
--preview 'git show --color=always (echo {} | cut -d" " -f4)' \
)
and set commit (echo $commitline | cut -d" " -f4)
and echo $commit

View File

@ -0,0 +1,10 @@
set -l current (git rev-parse --abbrev-ref HEAD | tr -d '\n')
set -l branch (git branch \
--format "%(refname:short)" \
| fzf \
--height 50% \
--header="On $current, $header" \
--preview-window right:70% \
--preview 'git log {} --color=always --pretty="format:%C(auto)%ar %h%d %s"' \
)
and echo $branch

View File

@ -0,0 +1,14 @@
if not count $argv >/dev/null
echo "Must provide filename."
return 1
end
set commitline ( git log \
--follow \
--pretty="format:%C(auto)%ar %h%d %s" \
-- ./$argv \
| fzf \
--height 100% \
--preview "git diff --color=always (echo {} | cut -d' ' -f4)^1..(echo {} | cut -d' ' -f4) -- ./$argv" \
)
and set commit (echo $commitline | cut -d" " -f4)
and echo $commit

View File

@ -0,0 +1,4 @@
set -l branch (git branch 2>/dev/null | grep '^\*' | colrm 1 2)
and set -l command "git push --set-upstream origin $branch"
and commandline -r $command
and commandline -f execute

View File

@ -0,0 +1,6 @@
set commitline (git log \
--pretty="format:%C(auto)%ar %h%d %s" \
| fzf \
)
and set commit (echo $commitline | cut -d" " -f4 )
and git show $commit

View File

@ -0,0 +1,37 @@
if contains f $argv
switch $argv[1]
case checkout
git-checkout-fuzzy
case add
git-add-fuzzy
case show
git-show-fuzzy
case merge
git-merge-fuzzy
case branch
if test "$argv[2]" = -d
git-delete-fuzzy
else if test "$argv[2]" = -D
git-force-delete-fuzzy
else
echo "Not a fuzzy option."
return 1
end
case reset
set commit (git-commits)
and if test "$argv[2]" = --hard
git reset --hard $commit
else
git reset $commit
end
case "*"
echo "No fuzzy option."
return 1
end
else
if count $argv >/dev/null
command git $argv
else
command git status -sb
end
end

View File

@ -0,0 +1,5 @@
if count $argv >/dev/null
curl ipinfo.io/$argv
else
curl checkip.amazonaws.com
end

View File

@ -0,0 +1,8 @@
if test -n "$filename"
vim $NOTES_PATH/$filename.md
else
set file (ls $NOTES_PATH | fzf)
if [ $status -eq 0 ]
vim $NOTES_PATH/$file
end
end

View File

@ -0,0 +1,4 @@
set vimfile (fd -t f --exec /usr/bin/stat -f "%m%t%N" | sort -nr | cut -f2 | fzf)
and set vimfile (echo $vimfile | tr -d '\r')
and commandline -r "vim $vimfile"
and commandline -f execute

View File

@ -0,0 +1,21 @@
set vimfile ( \
rg \
--color=always \
--line-number \
--no-heading \
--smart-case \
--iglob "!/Library/**" \
--iglob "!/System/**" \
--iglob "!Users/$HOME/Library/*" \
".*" \
| fzf --ansi \
--height "80%" \
--color "hl:-1:underline,hl+:-1:underline:reverse" \
--delimiter : \
--preview 'bat --color=always {1} --highlight-line {2}' \
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
)
and set line_number (echo $vimfile | tr -d '\r' | cut -d':' -f2)
and set vimfile (echo $vimfile | tr -d '\r' | cut -d':' -f1)
and commandline -r "vim +$line_number $vimfile"
and commandline -f execute

View File

@ -0,0 +1,7 @@
set current_dir $PWD
cd $NOTES_PATH
git pull
git add -A
git commit -m autosync
git push
cd $current_dir

View File

@ -0,0 +1,9 @@
echo "Searching git repos..." >&2
find "$HOME/dev" -type d -name '.git' | while read dir
set fullPath (dirname "$dir")
set relativePath (echo "$fullPath" | cut -d'/' -f5-)
if test -n (echo (git -C "$fullPath" status -s))
echo "$relativePath"
git -C "$fullPath" status -s
end
end