[Fix] cleanup
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
function __ssh_agent_is_started -d "check if ssh agent is already started"
|
||||
if test -n "$SSH_CONNECTION"
|
||||
# This is an SSH session
|
||||
ssh-add -l > /dev/null 2>&1
|
||||
if test $status -eq 0 -o $status -eq 1
|
||||
# An SSH agent was forwarded
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
if begin; test -f "$SSH_ENV"; and test -z "$SSH_AGENT_PID"; end
|
||||
source $SSH_ENV > /dev/null
|
||||
end
|
||||
|
||||
if test -z "$SSH_AGENT_PID"
|
||||
return 1
|
||||
end
|
||||
|
||||
ssh-add -l > /dev/null 2>&1
|
||||
if test $status -eq 2
|
||||
return 1
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
function __ssh_agent_start -d "start a new ssh agent"
|
||||
ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV
|
||||
chmod 600 $SSH_ENV
|
||||
source $SSH_ENV > /dev/null
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
function ask --description 'answer from cht.sh'
|
||||
curl -s https://cht.sh/$(string join '+' $argv[1..])
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
function bashs --description 'raw bash command'
|
||||
bash -c "$argv"
|
||||
end
|
||||
@@ -0,0 +1,30 @@
|
||||
function c2-worktree
|
||||
if test (count $argv) -ne 1
|
||||
echo "Usage: c2-worktree <branch-name>"
|
||||
echo "Example: c2-worktree package/package-update"
|
||||
return 1
|
||||
end
|
||||
|
||||
set branch $argv[1]
|
||||
|
||||
set root (git rev-parse --show-toplevel)
|
||||
or return 1
|
||||
set dir $root/.worktrees/(basename $branch)
|
||||
|
||||
mkdir -p $root/.worktrees
|
||||
or return 1
|
||||
|
||||
git checkout -b $branch
|
||||
or return 1
|
||||
|
||||
git checkout master
|
||||
or return 1
|
||||
|
||||
git worktree add $dir $branch
|
||||
or return 1
|
||||
|
||||
cd $dir
|
||||
or return 1
|
||||
|
||||
pnpm i
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
function clis --description 'fzf select cli'
|
||||
eval (cat $HOME/.config/misc/clis.txt | command fzf --multi)
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
function copy-commandline
|
||||
set -l cmd (commandline)
|
||||
if test -n "$cmd"
|
||||
if type -q pbcopy
|
||||
echo -n "$cmd" | pbcopy
|
||||
else if type -q xclip
|
||||
echo -n "$cmd" | xclip -selection clipboard
|
||||
else if type -q wl-copy
|
||||
echo -n "$cmd" | wl-copy
|
||||
end
|
||||
|
||||
# Provide brief visual feedback in the prompt
|
||||
set -l original_cmd (commandline)
|
||||
commandline -r "Copied!"
|
||||
sleep 0.4
|
||||
commandline -r "$original_cmd"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
function extract --description 'Extract any archive'
|
||||
switch $argv[1]
|
||||
case '*.tar' '*.tar.*' '*.tgz' '*.tbz2' '*.txz' # tar autodetects compression
|
||||
tar xf $argv[1]
|
||||
case '*.zip'
|
||||
unzip $argv[1]
|
||||
case '*.rar'
|
||||
unrar x $argv[1]
|
||||
case '*.7z'
|
||||
7z x $argv[1]
|
||||
case '*.gz'
|
||||
gunzip -k $argv[1]
|
||||
case '*.xz'
|
||||
unxz -k $argv[1]
|
||||
case '*.zst'
|
||||
unzstd $argv[1]
|
||||
case '*.bz2'
|
||||
bunzip2 -k $argv[1]
|
||||
case '*'
|
||||
echo "Unknown extension: $argv[1]"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
function fish_greeting
|
||||
#curl "wttr.in/Belgrade?format=%l:+%c+%t+|+%h+|+%w+|+(%%M+%m)\n"
|
||||
test -r ~/.config/fish/greet.txt; and cat ~/.config/fish/greet.txt ## populated by cronjob
|
||||
date +"📅 %d. %b 🕗 %H:%M - %A"
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
function fish_prompt
|
||||
if test -n "$SSH_TTY"
|
||||
echo -n (set_color brred)"$USER"(set_color white)'@'(set_color yellow)(prompt_hostname)' '
|
||||
end
|
||||
|
||||
echo -n (set_color blue)(prompt_pwd)' '
|
||||
|
||||
set_color -o
|
||||
if fish_is_root_user
|
||||
echo -n (set_color red)'# '
|
||||
end
|
||||
echo -n (set_color red)'❯'(set_color yellow)'❯'(set_color green)'❯ '
|
||||
set_color normal
|
||||
end
|
||||
@@ -0,0 +1,161 @@
|
||||
function fish_right_prompt
|
||||
set -l cmd_status $status
|
||||
if test $cmd_status -ne 0
|
||||
echo -n (set_color red)" $cmd_status"
|
||||
end
|
||||
|
||||
if not command -sq git
|
||||
set_color normal
|
||||
return
|
||||
end
|
||||
|
||||
# Get the git directory for later use.
|
||||
# Return if not inside a Git repository work tree.
|
||||
if not set -l git_dir (command git rev-parse --git-dir 2>/dev/null)
|
||||
set_color normal
|
||||
return
|
||||
end
|
||||
|
||||
# Get the current action ("merge", "rebase", etc.)
|
||||
# and if there's one get the current commit hash too.
|
||||
set -l commit ''
|
||||
if set -l action (fish_print_git_action "$git_dir")
|
||||
set commit (command git rev-parse HEAD 2> /dev/null | string sub -l 7)
|
||||
end
|
||||
|
||||
# Get either the branch name or a branch descriptor.
|
||||
set -l branch_detached 0
|
||||
if not set -l branch (command git symbolic-ref --short HEAD 2>/dev/null)
|
||||
set branch_detached 1
|
||||
set branch (command git describe --contains --all HEAD 2>/dev/null)
|
||||
end
|
||||
|
||||
# Get the commit difference counts between local and remote.
|
||||
command git rev-list --count --left-right 'HEAD...@{upstream}' 2>/dev/null \
|
||||
| read -d \t -l status_ahead status_behind
|
||||
if test $status -ne 0
|
||||
set status_ahead 0
|
||||
set status_behind 0
|
||||
end
|
||||
|
||||
# Get the stash status.
|
||||
# (git stash list) is very slow. => Avoid using it.
|
||||
set -l status_stashed 0
|
||||
if test -f "$git_dir/refs/stash"
|
||||
set status_stashed 1
|
||||
else if test -r "$git_dir/commondir"
|
||||
read -l commondir <"$git_dir/commondir"
|
||||
if test -f "$commondir/refs/stash"
|
||||
set status_stashed 1
|
||||
end
|
||||
end
|
||||
|
||||
# git-status' porcelain v1 format starts with 2 letters on each line:
|
||||
# The first letter (X) denotes the index state.
|
||||
# The second letter (Y) denotes the working directory state.
|
||||
#
|
||||
# The following table presents the possible combinations:
|
||||
# * The underscore character denotes whitespace.
|
||||
# * The cell values stand for the following file states:
|
||||
# a: added
|
||||
# d: deleted
|
||||
# m: modified
|
||||
# r: renamed
|
||||
# u: unmerged
|
||||
# t: untracked
|
||||
# * Cells with more than one letter signify that both states
|
||||
# are simultaneously the case. This is possible since the git index
|
||||
# and working directory operate independently of each other.
|
||||
# * Cells which are empty are unhandled by this code.
|
||||
# * T (= type change) is undocumented.
|
||||
# See Git v1.7.8.2 release notes for more information.
|
||||
#
|
||||
# \ Y→
|
||||
# X \
|
||||
# ↓ | A | C | D | M | R | T | U | X | B | ? | _
|
||||
# ----+----+----+----+----+----+----+----+----+----+----+----
|
||||
# A | u | | ad | am | r | am | u | | | | a
|
||||
# C | | | ad | am | r | am | u | | | | a
|
||||
# D | | | u | am | r | am | u | | | | a
|
||||
# M | | | ad | am | r | am | u | | | | a
|
||||
# R | r | r | rd | rm | r | rm | ur | r | r | r | r
|
||||
# T | | | ad | am | r | am | u | | | | a
|
||||
# U | u | u | u | um | ur | um | u | u | u | u | u
|
||||
# X | | | | m | r | m | u | | | |
|
||||
# B | | | | m | r | m | u | | | |
|
||||
# ? | | | | m | r | m | u | | | t |
|
||||
# _ | | | d | m | r | m | u | | | |
|
||||
set -l porcelain_status (command git status --porcelain 2>/dev/null | string sub -l2)
|
||||
|
||||
set -l status_added 0
|
||||
if string match -qr '[ACDMT][ MT]|[ACMT]D' $porcelain_status
|
||||
set status_added 1
|
||||
end
|
||||
set -l status_deleted 0
|
||||
if string match -qr '[ ACMRT]D' $porcelain_status
|
||||
set status_deleted 1
|
||||
end
|
||||
set -l status_modified 0
|
||||
if string match -qr '[MT]$' $porcelain_status
|
||||
set status_modified 1
|
||||
end
|
||||
set -l status_renamed 0
|
||||
if string match -qe R $porcelain_status
|
||||
set status_renamed 1
|
||||
end
|
||||
set -l status_unmerged 0
|
||||
if string match -qr 'AA|DD|U' $porcelain_status
|
||||
set status_unmerged 1
|
||||
end
|
||||
set -l status_untracked 0
|
||||
if string match -qe '\?\?' $porcelain_status
|
||||
set status_untracked 1
|
||||
end
|
||||
|
||||
set_color -o
|
||||
|
||||
if test -n "$branch"
|
||||
if test $branch_detached -ne 0
|
||||
set_color brmagenta
|
||||
else
|
||||
set_color green
|
||||
end
|
||||
echo -n " $branch"
|
||||
end
|
||||
if test -n "$commit"
|
||||
echo -n ' '(set_color yellow)"$commit"
|
||||
end
|
||||
if test -n "$action"
|
||||
set_color normal
|
||||
echo -n (set_color white)':'(set_color -o brred)"$action"
|
||||
end
|
||||
if test $status_ahead -ne 0
|
||||
echo -n ' '(set_color brmagenta)''
|
||||
end
|
||||
if test $status_behind -ne 0
|
||||
echo -n ' '(set_color brmagenta)''
|
||||
end
|
||||
if test $status_stashed -ne 0
|
||||
echo -n ' '(set_color cyan)''
|
||||
end
|
||||
if test $status_added -ne 0
|
||||
echo -n ' '(set_color green)''
|
||||
end
|
||||
if test $status_deleted -ne 0
|
||||
echo -n ' '(set_color red)''
|
||||
end
|
||||
if test $status_modified -ne 0
|
||||
echo -n ' '(set_color blue)''
|
||||
end
|
||||
if test $status_renamed -ne 0
|
||||
echo -n ' '(set_color magenta)''
|
||||
end
|
||||
if test $status_unmerged -ne 0
|
||||
echo -n ' '(set_color yellow)'═'
|
||||
end
|
||||
if test $status_untracked -ne 0
|
||||
echo -n ' '(set_color white)'◼'
|
||||
end
|
||||
|
||||
set_color normal
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
function fish_user_key_bindings
|
||||
# free Ctrl+S from terminal flow control (XOFF) so it can be bound below
|
||||
stty -ixon
|
||||
fish_default_key_bindings -M insert
|
||||
fish_vi_key_bindings --no-erase insert
|
||||
bind -M default ctrl-a beginning-of-line
|
||||
bind -M default ctrl-e end-of-line
|
||||
bind -M insert ctrl-space accept-autosuggestion
|
||||
bind -M insert ctrl-g 'git diff' repaint
|
||||
bind -M insert ctrl-o execute yazi
|
||||
bind -M insert ctrl-l clear-screen ls repaint
|
||||
bind -M default ctrl-s copy-commandline
|
||||
bind -M insert ctrl-s copy-commandline
|
||||
bind -M search ctrl-s copy-commandline
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
function fzfh --description 'Search history with fzf'
|
||||
history | fzf --query="$argv" --tac | read cmd
|
||||
if test -n "$cmd"
|
||||
echo $cmd
|
||||
commandline -r $cmd
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
function gcap --description 'Git add, commit with message, and push'
|
||||
git add .
|
||||
and git commit -m "$argv"
|
||||
and git push
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
function h --description "Colorized --help via bat"
|
||||
$argv --help 2>&1 | bat --plain --language=help
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
function lk --description 'linux knowledge'
|
||||
set -l DB "$HOME/projects/dmz/soft/lk/db.rec"
|
||||
set -l passes 0
|
||||
set -l count 0
|
||||
set -l query ""
|
||||
|
||||
while test $passes -lt 2; and test $count -eq 0
|
||||
set query (recsel "$DB" -p aim,tag | recsel -iq "$query" -CP aim,tag | sort -u | fzf --preview="recsel \"$DB\" -e \"aim~{}\" | bat")
|
||||
if test -n "$query"
|
||||
set count (recsel "$DB" -q "$query" -c)
|
||||
end
|
||||
set passes (math $passes + 1)
|
||||
end
|
||||
|
||||
if test $count -eq 1
|
||||
recsel "$DB" -q "$query" | recfmt -f "$HOME/projects/dmz/soft/lk/lists.fmt" | less
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
function opencodes --description 'contained opencode'
|
||||
bwrap \
|
||||
--unshare-all \
|
||||
--new-session \
|
||||
--clearenv \
|
||||
--die-with-parent \
|
||||
--share-net \
|
||||
--dev /dev \
|
||||
--proc /proc \
|
||||
--ro-bind /usr /usr \
|
||||
--ro-bind /lib /lib \
|
||||
--ro-bind /lib64 /lib64 \
|
||||
--ro-bind /bin /bin \
|
||||
--ro-bind /etc /etc \
|
||||
--ro-bind ~/.config/opencode ~/.config/opencode \
|
||||
--tmpfs /tmp/node-compile-cache \
|
||||
--bind ~/.local/state/opencode ~/.local/state/opencode \
|
||||
--bind ~/.local/share/opencode ~/.local/share/opencode \
|
||||
--bind "$(pwd)" "$(pwd)" \
|
||||
opencode
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
function ssh
|
||||
if type -q kitten
|
||||
kitten ssh $argv
|
||||
else
|
||||
command ssh $argv
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
function sshf --description 'fzf-pick an ssh host from ~/.ssh/config'
|
||||
# command fzf: bypass the fzf alias (its bat preview makes no sense for host names);
|
||||
# skip `Host *` wildcard blocks and take every alias on multi-name Host lines
|
||||
set -l host (awk '/^Host /{for (i = 2; i <= NF; i++) if ($i != "*") print $i}' ~/.ssh/config | command fzf)
|
||||
test -n "$host"; and ssh $host
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
function tuis --description 'fzf select tui'
|
||||
eval (cat $HOME/.config/misc/tuis.txt | command fzf --multi)
|
||||
end
|
||||
Reference in New Issue
Block a user