ref(nix): drop fish legacy support

This commit is contained in:
Léana 江 2024-01-19 20:11:36 +01:00 committed by Léana 江
parent 074e78751a
commit 1bec5057c7
21 changed files with 2 additions and 2 deletions

View file

@ -0,0 +1,92 @@
# OS-based aliases
switch (uname)
case "Linux"
alias chmod='chmod --preserve-root'
alias chown='chown --preserve-root'
abbr ss 'sudo systemctl'
case "Darwin"
alias hide_desktop='defaults write com.apple.finder CreateDesktop false; killall Finder'
alias show_desktop='defaults write com.apple.finder CreateDesktop true; killall Finder'
alias reset_launchpad='defaults write com.apple.dock ResetLaunchPad -bool true; killall Dock'
alias add_spacer_tile='defaults write com.apple.dock persistent-apps -array-add \'{tile-type="small-spacer-tile";}\'; killall Dock'
end
## idiot protection
alias rm='rm -i'
## Docker
abbr dc 'docker compose'
## Git
abbr gaa 'git add (git rev-parse --show-toplevel)'
abbr ga. 'git add .'
abbr gc 'git commit'
abbr gcl 'git clone'
abbr gl 'git log'
abbr gs 'git switch'
abbr gp 'git pull'
abbr gP 'git push'
abbr gpr 'git fetch && git rebase'
abbr gpm 'git fetch && git merge'
abbr clone 'clone_to_repos'
## FS
alias tree='tree -Cph'
## Editor
abbr ts tmux_sessionizer
abbr ta tmux_attach
abbr v nvim
abbr x hx
abbr se sudoedit
## brew
abbr bbb 'brew update && brew upgrade && brew autoremove && brew cleanup'
## Misc
alias restow='cd ~/.dotfiles/ && stow -D . && stow -S . && prevd'
abbr yt 'yt-dlp -f "b" --no-playlist \
-o "~/Downloads/%(title)s.%(ext)s" \
'
abbr ytpl 'yt-dlp -f "b" \
-o "~/Downloads/%(playlist_index)s - %(title)s.%(ext)s" \
'
abbr myip 'curl ipinfo.io'
abbr news newsboat
abbr :q exit
abbr :Q exit
# ssh
abbr pi 'ssh pi4'
abbr mainframe 'ssh mainframe'
## Preferences
abbr vp 'cd ~/.dotfiles/.config/nvim/after/plugin && $EDITOR ../../init.lua && prevd'
abbr fp 'cd ~/.dotfiles/.config/fish/functions && $EDITOR ../config.fish && prevd'
abbr tp '$EDITOR ~/.dotfiles/.tmux.conf'
abbr sp '$EDITOR ~/.dotfiles/.config/starship.toml'
# Home-Manager / NixOS
abbr np 'cd ~/.dotfiles/nix && $EDITOR flake.nix && prevd'
abbr ns 'sudo nixos-rebuild switch --flake ~/.dotfiles/nix#nixie'
abbr hp 'cd ~/.dotfiles/.config/home-manager && $EDITOR flake.nix && prevd'
abbr hs 'home-manager switch --flake ~/.dotfiles/nix#macOS'
# XMonad
abbr xp 'cd ~/.dotfiles/.config/xmonad && $EDITOR xmonad.hs && prevd'
abbr nsh 'nix-shell -p'
alias nix-shell 'nix-shell --run fish'
## Python
abbr vnew 'python3 -m venv venv && source venv/bin/activate.fish'
abbr von 'source venv/bin/activate.fish'
abbr voff 'deactivate'
# Search
abbr s 'search.py'
abbr syt 'search.py -m yt'
abbr sgh 'search.py -m gh'
abbr sfg 'search.py -m fg'
abbr swk 'search.py -m wk'
abbr sge 'search.py -m ge'

View file

@ -0,0 +1,4 @@
for mode in default insert
bind --mode $mode \cg tmux_home
bind --mode $mode \cf tmux_sessionizer
end

View file

@ -0,0 +1,95 @@
# Learn more: https://fishshell.com/docs/current/interactive.html
set -l black 000000
set -l grey a0a1a7
set -l cyan 0184bc
set -l blue 4078f2
set -l purple a626a4
set -l green 50a14f
set -l orange e45649
set -l red ca1243
set -l brown 986801
set -l gold c18401
set -l accent 645199
set -l visual d0d0d0
###########
# General #
###########
# default color
set fish_color_normal $black
# commands like echo
set fish_color_command $blue
# keywords like if - this falls back on the command color if unset
set fish_color_keyword $purple
# quoted text like "abc"
set fish_color_quote $green
# IO redirections like >/dev/null
set fish_color_redirection $gold
# process separators like ; and &
set fish_color_end $black --bold
# syntax errors
set fish_color_error $black
# ordinary command parameters
set fish_color_param $red
# parameters that are filenames (if the file exists)
set fish_color_valid_path --italics
# options starting with “-”, up to the first “--” parameter
set fish_color_option $cyan
# comments like # important
set fish_color_comment $grey
# selected text in vi visual mode
set fish_color_selection --background=$visual
# parameter expansion operators like * and ~
set fish_color_operator $orange
# character escapes like \n and \x70
set fish_color_escape $purple
# autosuggestions (the proposed rest of a command)
set fish_color_autosuggestion $grey
# The current working directory in the default prompt
set fish_color_cwd $black
# The current working directory in the default prompt for the root user
set fish_color_cwd_root $red
# The username in the default prompt
set fish_color_user $grey
# The hostname in the default prompt
set fish_color_host $black
# the hostname in the default prompt for remote sessions (like ssh)
set fish_color_host_remote $red
# the last commands nonzero exit code in the default prompt
set fish_color_status $red
# the ^C indicator on a canceled command
set fish_color_cancel $accent --reverse
# history search matches and selected pager items (background only)
set fish_color_search_match --background $visual
#########
# Pager #
#########
# the progress bar at the bottom left corner
set fish_pager_color_progress --reverse $cyan
# the background color of a line
set fish_pager_color_background $black
# the prefix string, i.e. the string that is to be completed
set fish_pager_color_prefix $black
# the completion itself, i.e. the proposed rest of the string
set fish_pager_color_completion $grey
# the completion description
set fish_pager_color_description $grey
# background of the selected completion
set fish_pager_color_selected_background $black
# prefix of the selected completion
set fish_pager_color_selected_prefix
# suffix of the selected completion
set fish_pager_color_selected_completion $red
# description of the selected completion
set fish_pager_color_selected_description $gold
# ## Alternating colors
# # background of every second unselected completion
# set fish_pager_color_secondary_background --background=$tinted_bg
# # prefix of every second unselected completion
# set fish_pager_color_secondary_prefix
# # suffix of every second unselected completion
# set fish_pager_color_secondary_completion
# # description of every second unselected completion
# set fish_pager_color_secondary_description

View file

@ -0,0 +1,14 @@
# zh_TW
# set -gx LANG zh_TW.UTF-8
# set -gx LANGUAGE zh_TW
# set -gx LC_ALL zh_TW.UTF-8
# fr_FR
# set -gx LANG fr_FR.UTF-8
# set -gx LANGUAGE fr_FR
# set -gx LC_ALL fr_FR.UTF-8
# en_US
set -gx LANG en_US.UTF-8
set -gx LANGUAGE en_US
set -gx LC_ALL en_US.UTF-8

View file

@ -10,7 +10,7 @@
foldl' (l: r: l + "\n" + r) ""
(
map
(n: readFile ../../../../.config/fish/conf.d/${n}.fish)
(n: readFile ./conf.d/${n}.fish)
ns
);
in
@ -29,7 +29,7 @@
(n: [
{
name = n;
value = {body = readFile ../../../../.config/fish/functions/${n}.fish;};
value = {body = readFile ./functions/${n}.fish;};
}
])
ns

View file

@ -0,0 +1,11 @@
function clone_to_repos
if count $argv > /dev/null
set name_repo (echo $argv | sed -E 's/.*[:\/]([[:alnum:]._-]+)\/([[:alnum:]._-]+).git$/\1 \2/')
set name (echo $name_repo | cut -d ' ' -f1)
set repo (echo $name_repo | cut -d ' ' -f2)
mkdir -p $REPOS_PATH/$name
git clone $argv $REPOS_PATH/$name/$repo
else
echo "Please provide a git url"
end
end

View file

@ -0,0 +1,6 @@
function commit_codewars
set name (basename (pwd))
set scope (basename (dirname (pwd)))
git commit -m "add($scope): $name"
end

View file

@ -0,0 +1,8 @@
function file_extension --description Obtain\ file\'s\ extension
if count $argv >/dev/null
echo (basename $argv) | sed 's/.*\(\.[^.]*$\)/\1/'
else
echo "Please supply a path"
return 1
end
end

View file

@ -0,0 +1,8 @@
function file_mantissa --description 'Obtain file name without extension'
if count $argv >/dev/null
echo (basename $argv) | sed 's/\.[^.]*$//'
else
echo "Please supply a path"
return 1
end
end

View file

@ -0,0 +1,17 @@
function fish_command_not_found
set hour (date +"%H")
set user (whoami)
set words \
"Are you drunk ??" \
"Il est seulement $hour heures" \
"Reveille-toi, $user" \
"Magique de vim !" \
"As-tu ecris ton journal aujourd'hui ?"
set choice $words[(random 1 (count $words))]
echo -e $choice | figlet -c
end

View file

@ -0,0 +1,14 @@
function fish_greeting
set_color --italics
switch $FISH_GREETING
case "toh"
cat ~/.quotes/toh/* | shuf -n 1
case "fleabag"
cat ~/.quotes/fleabag/* | shuf -n 1
case "date"
date
case "citation"
~/.local/bin/citation.py
case "*"
end
end

View file

@ -0,0 +1,8 @@
function fish_remove_path
if set index (contains -i $argv[1] $fish_user_path)
set --erase --universal fish_user_paths[$index]
echo "Updated fish_user_path: $fish_user_path"
else
echo "$argv[1] not found in fish_user_path: $fish_user_path"
end
end

View file

@ -0,0 +1,17 @@
function install_fisher --description 'Install fisher and its plugins'
# fisher
curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher
# versatile fzf search https://github.com/PatrickF1/fzf.fish
fisher install PatrickF1/fzf.fish
# https://github.com/PatrickF1/colored_man_pages.fish
fisher install patrickf1/colored_man_pages.fish
# # matching paired symbols https://github.com/laughedelic/pisces
# fisher install laughedelic/pisces
# only keep command that succeeded in history
fisher install meaningful-ooo/sponge
end

View file

@ -0,0 +1,30 @@
function largest-objects-in-repo
# Shows you the largest objects in your repo's pack file. Written for osx.
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs
# translated to fish with ChatGPT, reviewed by Léana :P
# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
set -x IFS "\n"
# list all objects including their size, sort by size, take top 10
set objects (git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head)
echo "All sizes are in kB. The pack column is the size of the object, compressed, inside the pack file."
set output "size,pack,SHA,location"
for obj in $objects
# extract the size in bytes
set size (math (echo $obj | cut -f 5 -d ' ') / 1024)
# extract the compressed size in bytes
set compressedSize (math (echo $obj | cut -f 6 -d ' ') / 1024)
# extract the SHA
set sha (echo $obj | cut -f 1 -d ' ')
# find the objects location in the repository tree
set other (git rev-list --all --objects | grep $sha)
#lineBreak=`echo -e "\n"`
set output "$output\n$size,$compressedSize,$other"
end
echo -e $output | column -t -s ', '
end

View file

@ -0,0 +1,3 @@
function snakecase
echo $argv | sed -E 's/[^A-Za-z0-9_\n]+/_/g' | sed -E 's/__+/_/g' | tr '[:upper:]' '[:lower:]'
end

View file

@ -0,0 +1,3 @@
function timestamp
date +%s
end

View file

@ -0,0 +1,22 @@
function tmux_attach --description "attach to existing tmux sessions"
# abandon if tmux not running
set tmux_running (pgrep tmux)
if [ -z "$tmux_running" ]
return 0
end
set selected (tmux list-sessions -F "#{session_name}" | fzf)
if [ -z $selected ]
return 0
end
set -U TMUX_LAST (tmux display-message -p '#S')
if [ -z $TMUX ]
tmux attach-session -t $selected
else
tmux switch-client -t $selected
end
end

View file

@ -0,0 +1,18 @@
function tmux_home
# create session if doesn't exist
if ! tmux has-session -t="home" 2> /dev/null
tmux \
new-session -ds "home" \; \
new-window -t "home" \; \
select-window -t "home":1
end
set -U TMUX_LAST (tmux display-message -p '#S')
if [ -z $TMUX ]
tmux attach-session -t "home"
else
tmux switch-client -t "home"
end
end

View file

@ -0,0 +1,17 @@
function tmux_last
# create session if doesn't exist
set session_name $TMUX_LAST
if ! tmux has-session -t=$session_name 2> /dev/null
tmux \
new-session -ds $session_name \; \
new-window -t $session_name \; \
select-window -t $session_name:1
end
set -U TMUX_LAST (tmux display-message -p '#S')
if [ -z $TMUX ]
tmux attach-session -t $session_name
else
tmux switch-client -t $session_name
end
end

View file

@ -0,0 +1,148 @@
# Inspired by the one and only primeagen
function tmux_sessionizer --description "create tmux sessions"
set selected \
# {{{
(begin
# use fd even thought it's an extra dependency because find is too slow
fd . $REPOS_PATH $UNIV_REPOS_PATH --exact-depth 2 --type d;
fd . $PLAYGROUND_PATH --exact-depth 1 --type d;
fd . $CODEWARS_PATH/Haskell --exact-depth 1 --type d;
fd . $CODEWARS_PATH/Rust --exact-depth 1 --type d;
fd . $CODEWARS_PATH/Python --exact-depth 1 --type d;
fd . $CODEWARS_PATH/C --exact-depth 1 --type d;
fd . $CODEWARS_PATH/Shell --exact-depth 1 --type d;
fd . $ZEROJUDGE_PATH --exact-depth 1 --type d;
echo "play";
echo "codewars haskell";
echo "codewars rust";
echo "codewars python";
echo "codewars c";
echo "codewars shell";
echo "zerojudge c";
end 2> /dev/null | sed -e "s|^$HOME|~|" | fzf)
# }}}
set selected (echo $selected | sed -e "s|^~|$HOME|")
if [ -z $selected ]
commandline --function repaint
return 0
end
switch $selected
case "play"
# {{{
read -P "Give it a name: " name
if test -z $name
return 0
else
set name (snakecase $name)
set selected ~/playground/$name/
mkdir -p $selected
end
# }}}
case "codewars rust"
# {{{
read -P "Give it a name: " name
if test -z $name
return 0
else
set kata_name (snakecase $name)
set selected $CODEWARS_PATH/Rust/$kata_name/
cargo new $selected --name codewars_$kata_name --vcs none
end
# }}}
case "codewars python"
# {{{
read -P "Give it a name: " name
if test -z $name
return 0
else
set name (snakecase $name)
set selected $CODEWARS_PATH/Python/$name/
mkdir -p $selected
touch $selected/main.py
end
# }}}
case "codewars haskell"
# {{{
read -P "Give it a name: " name
if test -z $name
return 0
else
set name (snakecase $name | tr '_' '-')
set selected $CODEWARS_PATH/Haskell/$name
cd $CODEWARS_PATH/Haskell ; \
stack new $name "https://git.earth2077.fr/leana/stack-templates/raw/branch/mistress/codewars.hsfiles" --resolver lts-21.13 ; \
prevd
end
# }}}
case "codewars c"
# {{{
read -P "Give it a name: " name
if test -z $name
return 0
else
set name (snakecase $name)
set selected $CODEWARS_PATH/C/$name/
mkdir -p $selected
touch $selected/main.c
echo "run:
gcc -I/opt/homebrew/include -L/opt/homebrew/lib -lcriterion main.c
./a.out" > $selected/makefile
end
# }}}
case "codewars shell"
# {{{
read -P "Give it a name: " name
if test -z $name
return 0
else
set name (snakecase $name)
set selected $CODEWARS_PATH/Shell/$name/
mkdir -p $selected
touch $selected/main.sh
end
# }}}
case "zerojudge c"
# {{{
read -P "Give it a name: " name
if test -z $name
return 0
else
set selected $ZEROJUDGE_PATH/$name/
mkdir -p $selected
touch $selected/main.c
end
# }}}
end
set session_name (echo $selected | tr . _)
# create session if doesn't exist
if ! tmux has -t=$session_name 2> /dev/null
tmux \
new-session -ds $session_name -c $selected \; \
send-keys -t $session_name $EDITOR ENTER \; \
new-window -t $session_name -c $selected \; \
select-window -t $session_name:1 \;
end
set -U TMUX_LAST (tmux display-message -p '#S')
if [ -z $TMUX ]
tmux attach-session -t $session_name
else
tmux switch-client -t $session_name
end
end
# vim:foldmethod=marker:foldlevel=0

View file

@ -0,0 +1,8 @@
function update_dotfiles
cd ~/.dotfiles/
git reset --hard
git pull --set-upstream origin main
git submodule update --init
prevd
restow
end