mirror of
https://github.com/nmasur/dotfiles
synced 2025-07-05 17:20:13 +00:00
move nixos and darwin back into modules dir
This commit is contained in:
55
modules/common/shell/bash/scripts/ocr.sh
Executable file
55
modules/common/shell/bash/scripts/ocr.sh
Executable file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Yoinked from https://github.com/JJGO/dotfiles
|
||||
# Adapted from https://github.com/sdushantha/bin
|
||||
|
||||
set -x
|
||||
TEXT_FILE="/tmp/ocr.txt"
|
||||
IMAGE_FILE="/tmp/ocr.png"
|
||||
|
||||
function notify-send() {
|
||||
/usr/bin/osascript -e "display notification \"$2\" with title \"OCR\""
|
||||
}
|
||||
|
||||
PATH="/usr/local/bin/:$PATH"
|
||||
|
||||
# Take screenshot by selecting the area
|
||||
/usr/sbin/screencapture -i "$IMAGE_FILE"
|
||||
|
||||
# Get the exit code of the previous command.
|
||||
# So in this case, it is the screenshot command. If it did not exit with an
|
||||
# exit code 0, then it means the user canceled the process of taking a
|
||||
# screenshot by doing something like pressing the escape key
|
||||
STATUS=$?
|
||||
|
||||
# If the user pressed the escape key or did something to terminate the proccess
|
||||
# taking a screenshot, then just exit
|
||||
[ $STATUS -ne 0 ] && exit 1
|
||||
|
||||
# Do the magic (∩^o^)⊃━☆゚.*・。゚
|
||||
# Notice how I have removing the extension .txt from the file path. This is
|
||||
# because tesseract adds .txt to the given file path anyways. So if we were to
|
||||
# specify /tmp/ocr.txt as the file path, tesseract would out the text to
|
||||
# /tmp/ocr.txt.txt
|
||||
tesseract "$IMAGE_FILE" "${TEXT_FILE//\.txt/}"
|
||||
|
||||
# Check if the text was detected by checking number
|
||||
# of lines in the file
|
||||
LINES=$(wc -l <$TEXT_FILE)
|
||||
if [ "$LINES" -eq 0 ]; then
|
||||
notify-send "ocr" "no text was detected"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Copy text to clipboard
|
||||
# xclip -selection clip < "$TEXT_FILE"
|
||||
/usr/bin/pbcopy <"$TEXT_FILE"
|
||||
|
||||
# Send a notification with the text that was grabbed using OCR
|
||||
notify-send "ocr" "$(cat $TEXT_FILE)"
|
||||
|
||||
# Clean up
|
||||
# "Always leave the area better than you found it"
|
||||
# - My first grade teacher
|
||||
rm "$TEXT_FILE"
|
||||
rm "$IMAGE_FILE"
|
15
modules/common/shell/charm.nix
Normal file
15
modules/common/shell/charm.nix
Normal file
@ -0,0 +1,15 @@
|
||||
{ config, pkgs, lib, ... }: {
|
||||
|
||||
options.charm.enable = lib.mkEnableOption "Charm utilities.";
|
||||
|
||||
config.home-manager.users.${config.user} = lib.mkIf config.charm.enable {
|
||||
|
||||
home.packages = with pkgs; [
|
||||
glow # Markdown previews
|
||||
skate # Key-value store
|
||||
charm # Manage account and filesystem
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
}
|
13
modules/common/shell/default.nix
Normal file
13
modules/common/shell/default.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{ ... }: {
|
||||
imports = [
|
||||
./charm.nix
|
||||
./direnv.nix
|
||||
./fish
|
||||
./fzf.nix
|
||||
./git.nix
|
||||
./github.nix
|
||||
./nixpkgs.nix
|
||||
./starship.nix
|
||||
./utilities.nix
|
||||
];
|
||||
}
|
9
modules/common/shell/direnv.nix
Normal file
9
modules/common/shell/direnv.nix
Normal file
@ -0,0 +1,9 @@
|
||||
{ config, ... }: {
|
||||
|
||||
home-manager.users.${config.user}.programs.direnv = {
|
||||
enable = true;
|
||||
nix-direnv.enable = true;
|
||||
config = { whitelist = { prefix = [ config.dotfilesPath ]; }; };
|
||||
};
|
||||
|
||||
}
|
131
modules/common/shell/fish/default.nix
Normal file
131
modules/common/shell/fish/default.nix
Normal 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;
|
||||
|
||||
};
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
set commit (git-commits)
|
||||
if [ $commit ]
|
||||
commandline -i "$commit"
|
||||
else
|
||||
commandline -i HEAD
|
||||
end
|
4
modules/common/shell/fish/functions/edit.fish
Normal file
4
modules/common/shell/fish/functions/edit.fish
Normal 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
|
10
modules/common/shell/fish/functions/fcd.fish
Normal file
10
modules/common/shell/fish/functions/fcd.fish
Normal 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
|
@ -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
|
122
modules/common/shell/fish/functions/fish_vi_cursor.fish
Normal file
122
modules/common/shell/fish/functions/fish_vi_cursor.fish
Normal 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
|
14
modules/common/shell/fish/functions/git-add-fuzzy.fish
Normal file
14
modules/common/shell/fish/functions/git-add-fuzzy.fish
Normal 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
|
8
modules/common/shell/fish/functions/git-commits.fish
Normal file
8
modules/common/shell/fish/functions/git-commits.fish
Normal 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
|
10
modules/common/shell/fish/functions/git-fuzzy-branch.fish
Normal file
10
modules/common/shell/fish/functions/git-fuzzy-branch.fish
Normal 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
|
14
modules/common/shell/fish/functions/git-history.fish
Normal file
14
modules/common/shell/fish/functions/git-history.fish
Normal 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
|
@ -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
|
6
modules/common/shell/fish/functions/git-show-fuzzy.fish
Normal file
6
modules/common/shell/fish/functions/git-show-fuzzy.fish
Normal 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
|
37
modules/common/shell/fish/functions/git.fish
Normal file
37
modules/common/shell/fish/functions/git.fish
Normal 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
|
5
modules/common/shell/fish/functions/ip.fish
Normal file
5
modules/common/shell/fish/functions/ip.fish
Normal file
@ -0,0 +1,5 @@
|
||||
if count $argv >/dev/null
|
||||
curl ipinfo.io/$argv
|
||||
else
|
||||
curl checkip.amazonaws.com
|
||||
end
|
8
modules/common/shell/fish/functions/note.fish
Normal file
8
modules/common/shell/fish/functions/note.fish
Normal 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
|
4
modules/common/shell/fish/functions/recent.fish
Normal file
4
modules/common/shell/fish/functions/recent.fish
Normal 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
|
21
modules/common/shell/fish/functions/search-and-edit.fish
Normal file
21
modules/common/shell/fish/functions/search-and-edit.fish
Normal 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
|
7
modules/common/shell/fish/functions/syncnotes.fish
Normal file
7
modules/common/shell/fish/functions/syncnotes.fish
Normal 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
|
9
modules/common/shell/fish/functions/uncommitted.fish
Normal file
9
modules/common/shell/fish/functions/uncommitted.fish
Normal 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
|
41
modules/common/shell/fzf.nix
Normal file
41
modules/common/shell/fzf.nix
Normal file
@ -0,0 +1,41 @@
|
||||
{ config, ... }: {
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
programs.fzf.enable = true;
|
||||
|
||||
programs.fish = {
|
||||
functions = {
|
||||
projects = {
|
||||
description = "Jump to a project";
|
||||
body = ''
|
||||
set projdir ( \
|
||||
fd \
|
||||
--search-path $HOME/dev \
|
||||
--type directory \
|
||||
--hidden \
|
||||
"^.git\$" \
|
||||
| xargs dirname \
|
||||
| fzf \
|
||||
--delimiter '/' \
|
||||
--with-nth 6.. \
|
||||
)
|
||||
and cd $projdir
|
||||
and commandline -f execute
|
||||
'';
|
||||
};
|
||||
};
|
||||
shellAbbrs = { lsf = "ls -lh | fzf"; };
|
||||
};
|
||||
|
||||
# Global fzf configuration
|
||||
home.sessionVariables = let fzfCommand = "fd --type file";
|
||||
in {
|
||||
FZF_DEFAULT_COMMAND = fzfCommand;
|
||||
FZF_CTRL_T_COMMAND = fzfCommand;
|
||||
FZF_DEFAULT_OPTS = "-m --height 50% --border";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
129
modules/common/shell/git.nix
Normal file
129
modules/common/shell/git.nix
Normal file
@ -0,0 +1,129 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let home-packages = config.home-manager.users.${config.user}.home.packages;
|
||||
|
||||
in {
|
||||
|
||||
options = {
|
||||
gitName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Name to use for git commits";
|
||||
};
|
||||
gitEmail = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Email to use for git commits";
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
|
||||
home-manager.users.root.programs.git = {
|
||||
enable = true;
|
||||
extraConfig.safe.directory = config.dotfilesPath;
|
||||
};
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
programs.git = {
|
||||
enable = true;
|
||||
userName = config.gitName;
|
||||
userEmail = config.gitEmail;
|
||||
extraConfig = {
|
||||
pager = { branch = "false"; };
|
||||
safe = { directory = config.dotfilesPath; };
|
||||
pull = { ff = "only"; };
|
||||
init = { defaultBranch = "master"; };
|
||||
};
|
||||
ignores = [ ".direnv/**" "result" ];
|
||||
};
|
||||
|
||||
programs.fish.shellAbbrs = {
|
||||
g = "git";
|
||||
gs = "git status";
|
||||
gd = "git diff";
|
||||
gds = "git diff --staged";
|
||||
gdp = "git diff HEAD^";
|
||||
ga = "git add";
|
||||
gaa = "git add -A";
|
||||
gac = "git commit -am";
|
||||
gc = "git commit -m";
|
||||
gca = "git commit --amend --no-edit";
|
||||
gcae = "git commit --amend";
|
||||
gu = "git pull";
|
||||
gp = "git push";
|
||||
gpp = "git-push-upstream";
|
||||
gl = "git log --graph --decorate --oneline -20";
|
||||
gll = "git log --graph --decorate --oneline";
|
||||
gco = "git checkout";
|
||||
gcom = ''
|
||||
git switch (git symbolic-ref refs/remotes/origin/HEAD | cut -d"/" -f4)'';
|
||||
gcob = "git switch -c";
|
||||
gb = "git branch";
|
||||
gbd = "git branch -d";
|
||||
gbD = "git branch -D";
|
||||
gr = "git reset";
|
||||
grh = "git reset --hard";
|
||||
gm = "git merge";
|
||||
gcp = "git cherry-pick";
|
||||
cdg = "cd (git rev-parse --show-toplevel)";
|
||||
};
|
||||
|
||||
# Required for fish commands
|
||||
home.packages = with pkgs; [ fish fzf bat ];
|
||||
|
||||
programs.fish.functions = lib.mkIf (builtins.elem pkgs.fzf home-packages
|
||||
&& builtins.elem pkgs.bat home-packages) {
|
||||
git = { body = builtins.readFile ./fish/functions/git.fish; };
|
||||
git-add-fuzzy = {
|
||||
body = builtins.readFile ./fish/functions/git-add-fuzzy.fish;
|
||||
};
|
||||
git-fuzzy-branch = {
|
||||
argumentNames = "header";
|
||||
body = builtins.readFile ./fish/functions/git-fuzzy-branch.fish;
|
||||
};
|
||||
git-checkout-fuzzy = {
|
||||
body = ''
|
||||
set branch (git-fuzzy-branch "checkout branch...")
|
||||
and git checkout $branch
|
||||
'';
|
||||
};
|
||||
git-delete-fuzzy = {
|
||||
body = ''
|
||||
set branch (git-fuzzy-branch "delete branch...")
|
||||
and git branch -d $branch
|
||||
'';
|
||||
};
|
||||
git-force-delete-fuzzy = {
|
||||
body = ''
|
||||
set branch (git-fuzzy-branch "force delete branch...")
|
||||
and git branch -D $branch
|
||||
'';
|
||||
};
|
||||
git-merge-fuzzy = {
|
||||
body = ''
|
||||
set branch (git-fuzzy-branch "merge from...")
|
||||
and git merge $branch
|
||||
'';
|
||||
};
|
||||
git-show-fuzzy = {
|
||||
body = builtins.readFile ./fish/functions/git-show-fuzzy.fish;
|
||||
};
|
||||
git-commits = {
|
||||
body = builtins.readFile ./fish/functions/git-commits.fish;
|
||||
};
|
||||
git-history = {
|
||||
body = builtins.readFile ./fish/functions/git-history.fish;
|
||||
};
|
||||
git-push-upstream = {
|
||||
description = "Create upstream branch";
|
||||
body = builtins.readFile ./fish/functions/git-push-upstream.fish;
|
||||
};
|
||||
uncommitted = {
|
||||
description = "Find uncommitted git repos";
|
||||
body = builtins.readFile ./fish/functions/uncommitted.fish;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
77
modules/common/shell/github.nix
Normal file
77
modules/common/shell/github.nix
Normal file
@ -0,0 +1,77 @@
|
||||
{ config, pkgs, lib, ... }: {
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
programs.gh =
|
||||
lib.mkIf config.home-manager.users.${config.user}.programs.git.enable {
|
||||
enable = true;
|
||||
enableGitCredentialHelper = true;
|
||||
settings.git_protocol = "https";
|
||||
};
|
||||
|
||||
programs.fish =
|
||||
lib.mkIf config.home-manager.users.${config.user}.programs.gh.enable {
|
||||
shellAbbrs = {
|
||||
ghr = "gh repo view -w";
|
||||
gha =
|
||||
"gh run list | head -1 | awk '{ print $(NF-2) }' | xargs gh run view";
|
||||
grw = "gh run watch";
|
||||
grf = "gh run view --log-failed";
|
||||
grl = "gh run view --log";
|
||||
ghpr = "gh pr create && sleep 3 && gh run watch";
|
||||
};
|
||||
functions = {
|
||||
repos = {
|
||||
description = "Clone GitHub repositories";
|
||||
argumentNames = "organization";
|
||||
body = ''
|
||||
set directory (gh-repos $organization)
|
||||
and cd $directory
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
home.packages = [
|
||||
(pkgs.writeShellScriptBin "gh-repos" ''
|
||||
case $1 in
|
||||
t2) organization="take-two" ;;
|
||||
d2c) organization="take-two-t2gp" ;;
|
||||
t2gp) organization="take-two-t2gp" ;;
|
||||
pd) organization="private-division" ;;
|
||||
dots) organization="playdots" ;;
|
||||
*) organization="nmasur" ;;
|
||||
esac
|
||||
|
||||
selected=$(gh repo list "$organization" \
|
||||
--limit 50 \
|
||||
--no-archived \
|
||||
--json=name,description,isPrivate,updatedAt,primaryLanguage \
|
||||
| jq -r '.[] | .name + "," + if .description == "" then "-" else .description |= gsub(","; " ") | .description end + "," + .updatedAt + "," + .primaryLanguage.name' \
|
||||
| (echo "REPO,DESCRIPTION,UPDATED,LANGUAGE"; cat -) \
|
||||
| column -s , -t \
|
||||
| fzf \
|
||||
--header-lines=1 \
|
||||
--layout=reverse \
|
||||
--bind "ctrl-o:execute:gh repo view -w ''${organization}/{1}" \
|
||||
--bind "shift-up:preview-half-page-up" \
|
||||
--bind "shift-down:preview-half-page-down" \
|
||||
--preview "GH_FORCE_TTY=49% gh repo view ''${organization}/{1} | glow -" \
|
||||
--preview-window up
|
||||
)
|
||||
[ -n "''${selected}" ] && {
|
||||
directory="$HOME/dev/work"
|
||||
if [ $organization = "nmasur" ]; then directory="$HOME/dev/personal"; fi
|
||||
repo=$(echo "''${selected}" | awk '{print $1}')
|
||||
repo_full="''${organization}/''${repo}"
|
||||
if [ ! -d "''${directory}/''${repo}" ]; then
|
||||
gh repo clone "$repo_full" "''${directory}/''${repo}"
|
||||
fi
|
||||
echo "''${directory}/''${repo}"
|
||||
}
|
||||
'')
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
}
|
72
modules/common/shell/nixpkgs.nix
Normal file
72
modules/common/shell/nixpkgs.nix
Normal file
@ -0,0 +1,72 @@
|
||||
{ config, pkgs, lib, ... }: {
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
programs.fish = {
|
||||
shellAbbrs = {
|
||||
n = "nix";
|
||||
ns = "nix-shell -p";
|
||||
nsf = "nix-shell --run fish -p";
|
||||
nsr = "nix-shell-run";
|
||||
nps = "nix repl '<nixpkgs>'";
|
||||
nixo = "man configuration.nix";
|
||||
nixh = "man home-configuration.nix";
|
||||
nr = "rebuild-nixos";
|
||||
nro = "rebuild-nixos offline";
|
||||
hm = "rebuild-home";
|
||||
};
|
||||
functions = {
|
||||
nix-shell-run = {
|
||||
body = ''
|
||||
set program $argv[1]
|
||||
if test (count $argv) -ge 2
|
||||
commandline -r "nix run nixpkgs#$program -- $argv[2..-1]"
|
||||
else
|
||||
commandline -r "nix run nixpkgs#$program"
|
||||
end
|
||||
commandline -f execute
|
||||
'';
|
||||
};
|
||||
nix-fzf = {
|
||||
body = ''
|
||||
commandline -i (nix-instantiate --eval --json \
|
||||
-E 'builtins.attrNames (import <nixpkgs> {})' \
|
||||
| jq '.[]' -r | fzf)
|
||||
commandline -f repaint
|
||||
'';
|
||||
};
|
||||
rebuild-nixos = {
|
||||
body = ''
|
||||
if test "$argv[1]" = "offline"
|
||||
set option "--option substitute false"
|
||||
end
|
||||
git -C ${config.dotfilesPath} add --intent-to-add --all
|
||||
commandline -r "doas nixos-rebuild switch $option --flake ${config.dotfilesPath}#${config.networking.hostName}"
|
||||
commandline --function execute
|
||||
'';
|
||||
};
|
||||
rebuild-home = {
|
||||
body = ''
|
||||
git -C ${config.dotfilesPath} add --intent-to-add --all
|
||||
commandline -r "${pkgs.home-manager}/bin/home-manager switch --flake ${config.dotfilesPath}#${config.networking.hostName}";
|
||||
commandline --function execute
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Provides "command-not-found" options
|
||||
programs.nix-index = {
|
||||
enable = true;
|
||||
enableFishIntegration = true;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
nix = {
|
||||
|
||||
# Set channel to flake packages, used for nix-shell commands
|
||||
nixPath = [ "nixpkgs=${pkgs.path}" ];
|
||||
|
||||
};
|
||||
|
||||
}
|
63
modules/common/shell/starship.nix
Normal file
63
modules/common/shell/starship.nix
Normal file
@ -0,0 +1,63 @@
|
||||
{ config, lib, ... }: {
|
||||
|
||||
home-manager.users.${config.user}.programs.starship = {
|
||||
enable = true;
|
||||
settings = {
|
||||
add_newline = false; # Don't print new line at the start of the prompt
|
||||
format = lib.concatStrings [
|
||||
"$directory"
|
||||
"$git_branch"
|
||||
"$git_commit"
|
||||
"$git_status"
|
||||
"$hostname"
|
||||
"$cmd_duration"
|
||||
"$character"
|
||||
];
|
||||
right_format = "$nix_shell";
|
||||
character = {
|
||||
success_symbol = "[❯](bold green)";
|
||||
error_symbol = "[❯](bold red)";
|
||||
vicmd_symbol = "[❮](bold green)";
|
||||
};
|
||||
cmd_duration = {
|
||||
min_time = 5000;
|
||||
show_notifications = true;
|
||||
min_time_to_notify = 30000;
|
||||
format = "[$duration]($style) ";
|
||||
};
|
||||
directory = {
|
||||
truncate_to_repo = true;
|
||||
truncation_length = 100;
|
||||
};
|
||||
git_branch = { format = "[$symbol$branch]($style)"; };
|
||||
git_commit = {
|
||||
format = "( @ [$hash]($style) )";
|
||||
only_detached = false;
|
||||
};
|
||||
git_status = {
|
||||
format = "([$all_status$ahead_behind]($style) )";
|
||||
conflicted = "=";
|
||||
ahead = "⇡";
|
||||
behind = "⇣";
|
||||
diverged = "⇕";
|
||||
untracked = "⋄";
|
||||
stashed = "⩮";
|
||||
modified = "∽";
|
||||
staged = "+";
|
||||
renamed = "»";
|
||||
deleted = "✘";
|
||||
style = "red";
|
||||
};
|
||||
hostname = {
|
||||
ssh_only = true;
|
||||
format = "on [$hostname](bold red) ";
|
||||
};
|
||||
nix_shell = {
|
||||
format = "[$symbol $name]($style)";
|
||||
symbol = "❄️";
|
||||
};
|
||||
python = { format = "[\${version}\\(\${virtualenv}\\)]($style)"; };
|
||||
};
|
||||
};
|
||||
|
||||
}
|
82
modules/common/shell/utilities.nix
Normal file
82
modules/common/shell/utilities.nix
Normal file
@ -0,0 +1,82 @@
|
||||
{ config, pkgs, ... }:
|
||||
|
||||
let
|
||||
|
||||
ignorePatterns = ''
|
||||
!.env*
|
||||
!.github/
|
||||
!.gitignore
|
||||
!*.tfvars
|
||||
.terraform/
|
||||
.target/
|
||||
/Library/'';
|
||||
|
||||
in {
|
||||
|
||||
config = {
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
# Fix: age won't build
|
||||
nixpkgs.overlays = [
|
||||
(final: prev: {
|
||||
age = prev.age.overrideAttrs (old: {
|
||||
src = prev.fetchFromGitHub {
|
||||
owner = "FiloSottile";
|
||||
repo = "age";
|
||||
rev = "7354aa0d08a06eac42c635670a55f858bd23c943";
|
||||
sha256 = "H80mNTgZmExDMgubONIXP7jmLBvNMVqXee6NiZJhPFY=";
|
||||
};
|
||||
});
|
||||
})
|
||||
];
|
||||
|
||||
home.packages = with pkgs; [
|
||||
unzip # Extract zips
|
||||
rsync # Copy folders
|
||||
ripgrep # grep
|
||||
fd # find
|
||||
sd # sed
|
||||
jq # JSON manipulation
|
||||
tealdeer # Cheatsheets
|
||||
tree # View directory hierarchy
|
||||
htop # Show system processes
|
||||
glow # Pretty markdown previews
|
||||
qrencode # Generate qr codes
|
||||
vimv-rs # Batch rename files
|
||||
dig # DNS lookup
|
||||
lf # File viewer
|
||||
inetutils # Includes telnet, whois
|
||||
age # Encryption
|
||||
];
|
||||
|
||||
programs.zoxide.enable = true; # Shortcut jump command
|
||||
|
||||
home.file = {
|
||||
".rgignore".text = ignorePatterns;
|
||||
".fdignore".text = ignorePatterns;
|
||||
".digrc".text = "+noall +answer"; # Cleaner dig commands
|
||||
};
|
||||
|
||||
programs.bat = {
|
||||
enable = true; # cat replacement
|
||||
config = { theme = config.theme.colors.batTheme; };
|
||||
};
|
||||
|
||||
programs.fish.shellAbbrs = {
|
||||
cat = "bat"; # Swap cat with bat
|
||||
};
|
||||
|
||||
programs.fish.functions = {
|
||||
ping = {
|
||||
description = "Improved ping";
|
||||
argumentNames = "target";
|
||||
body = "${pkgs.prettyping}/bin/prettyping --nolegend $target";
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user