New funcs, new starship and vim tweaks

Fixes vim-in-intellij-terminal bug!
This commit is contained in:
Sage Vaillancourt 2025-02-13 14:04:50 -05:00
parent bbc9e67475
commit 9015815872
4 changed files with 168 additions and 23 deletions

View File

@ -1,5 +1,4 @@
format = """
$git_status\
${custom.username}\
$hostname\
$shlvl\
@ -43,11 +42,11 @@ $cmake\
$nix_shell\
$conda\
$memory_usage\
$aws\
$gcloud\
$openstack\
$env_var\
$crystal\
$git_status\
$line_break\
$lua\
$jobs\
@ -67,10 +66,11 @@ truncate_to_repo = false
truncation_length = 0
[nodejs]
format = "$symbol"
format = "$symbol$version"
[java]
format = "$symbol"
symbol = ""
format = "$symbol $version "
[time]
disabled = true
@ -117,12 +117,12 @@ format = '[$ssh_symbol](bold blue) [$hostname](bold dimmed green) '
conflicted = "=conflicted "
ahead = "⇡ahead "
behind = "⇣behind "
diverged = "⇕diverged "
untracked = "?untracked "
stashed = "\\$stashed "
modified = "!modified "
diverged = "⇕dvrgd "
untracked = "?untrckd "
stashed = "\\$tashed "
modified = "!mdfd "
staged = "[++($count)](green)"
renamed = "»renamed "
deleted = "✘deleted "
format = "[$all_status]($style)\n"
style = 'red dimmed'
renamed = "»rnmd "
deleted = "✘dltd "
format = "[$all_status]($style)"
style = 'black dimmed'

View File

@ -13,6 +13,23 @@ alias _slides="$(which slides 2> /dev/null || echo "echo 'slides not installed'"
CASCH_DIR="$HOME/.casch"
CASCH_MAP="$CASCH_DIR/.base-map.json"
_vim="$(which vim)"
function vim {
if command -v nvim && [[ "$1" =~ ".*.lua" ]]; then
nvim "$1"
else
"$_vim" "$1"
fi
}
function vim-temp {
rm ~/.vim-temp-file &> /dev/null
vim ~/.vim-temp-file
cat ~/.vim-temp-file
}
alias vimtemp='vim-temp'
function git-worked {
author="$1"
since="$2"
@ -195,6 +212,7 @@ function pwgen {
}
alias k='kubectl'
alias kick='kubectl rollout restart deployment'
function kube-pod-name {
local pods="$(kubectl get pods | grep "$1")"
@ -429,7 +447,41 @@ alias du='du -sh'
alias tags='ctags --exclude=node_modules -f newtags -R . && mv newtags tags'
function js {
load_nvm; node -e "const stdin = process.openStdin(); let data = \"\"; stdin.on(\"data\", chunk => data += chunk); stdin.on(\"end\", () => console.log(JSON.stringify(($@)(data), null, 2)));"
local input="$(cat)"
local commText=""
while [ "$#" -gt 0 ]; do
case "$1" in
-h | --help)
echo "Reads stdin as a string passes it to the given function."
return 0
;;
*)
commText="$commText$1"
shift 1
;;
esac
done
local callback=""
if [[ "$commText" == "" ]]; then
echo -n "js> "
load_nvm
while IFS= read -r line </dev/tty && [[ "$line" != "" ]]; do
commText="$(echo -E "$commText"; echo -E "$line")"
echo -n "js> "
done
# TODO: Append to a histfile of some kind?
else
load_nvm
fi
echo "$input" | node -e "const stdin = process.openStdin(); let data = \"\"; stdin.on(\"data\", chunk => data += chunk); stdin.on(\"end\", () => console.log(JSON.stringify(($commText)(data), null, 2)));"
# TODO? Write actual JS into bash history with a HEREDOC?
# fc -W
# fc -R
}
function roll {
@ -466,6 +518,93 @@ alias 12='roll 12'
alias d20='roll 20'
alias 20='roll 20'
function has-diff {
! diff "$1" "$2"
}
function until-no-change {
local regex="$1"
local file="$2"
echo
echo perl -0pe "$regex" "$file"
perl -0pe "$regex" "$file" > .tmp
while has-diff .tmp "$file" &> /dev/null; do
perl -0pe "$regex" ".tmp" > "$file"
perl -0pe "$regex" "$file" > .tmp
done
mv .tmp "$file"
}
function external-above-internal {
local file="$1"
local regex="s#((?:import.*'(?:\.|@/).*\n)+)\n?((?:import.*'([a-z]|@[^/]).*\n)+)#\2\1#gm;"
until-no-change "$regex" "$file"
}
function absolute-above-relative {
local file="$1"
local regex="s#((?:import.*'\..*\n)+)\n?((?:import.*'@/.*\n)+)#\2\1#gm"
until-no-change "$regex" "$file"
}
function fix-imports {
local file="$1"
external-above-internal "$file"
absolute-above-relative "$file"
}
function fix-all-imports {
find -type f \( -name '*.ts' -o -name "*.js" -o -name "*.jsx" -o -name "*.tsx" \) | grep -v 'node_modules\|generated\|jest' | while read -r file; do
fix-imports "$file"
done
}
function lazy-nvm-use {
local target="$1"
if ! node --version | sed 's/^v//' | grep "^$target" &> /dev/null; then
nvm use "$target"
fi
}
function cd {
builtin cd $@ || return $?
local ret="$?"
if ! test -f Makefile; then
return 0
fi
local build_env="$(make get-build-environment 2> /dev/null)"
case "$build_env" in
NODE_*)
load_nvm
lazy-nvm-use "$(echo "$build_env" | sed 's/NODE_//')"
;;
JAVA_*)
local java_version="$(echo "$build_env" | sed 's/[^0-9]//g')"
if [[ "$java_version" != "" ]]; then
# If anyone puts malicious scripts into get-build-environment, we're screwed.
export JAVA_HOME="$(eval "echo \$JAVA_$java_version")"
else
export JAVA_HOME="$JAVA_8"
fi
;;
*)
if test -d node_modules && test -d package.json; then
load_nvm; lazy-nvm-use 14
elif test -f pom.xml; then
export JAVA_HOME="$JAVA_8"
fi
;;
esac
return 0
}
if [[ "$@" != "" ]]; then
$@
fi

View File

@ -11,15 +11,19 @@ set tags=./tags;/ " Search up to / for tags file
set updatetime=100
set clipboard=unnamedplus " Use system clipboard
if empty($DISPLAY) && empty($SSH_CONNECTION)
colorscheme monokai
syntax enable
else
set termguicolors
let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"
colorscheme monokai
syntax enable
if ! has('nvim')
if empty($DISPLAY) && empty($SSH_CONNECTION)
colorscheme monokai
syntax enable
else
set termguicolors
if $TERMINAL_EMULATOR != "JetBrains-JediTerm"
let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"
endif
colorscheme monokai
syntax enable
endif
endif
let mapleader=" "

View File

@ -324,7 +324,9 @@ function _getdot {
}
function getdot {
lockfor "$SYNC_LOCK_FILE" 90 _getdot $@
if ping -c 1 -i 2 git.sagev.space; then
lockfor "$SYNC_LOCK_FILE" 90 _getdot $@
fi
}
if [[ "$OS" != "Windows_NT" ]] && which starship &> /dev/null; then