mirror of
https://github.com/tiyn/dotfiles.git
synced 2026-05-09 05:51:35 +02:00
Zsh/Nvim: python is now mapped to uv run python using Zsh widgets and the compiler script for Nvim
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# HELPER FUNCTIONS #
|
# HELPER FUNCTIONS #
|
||||||
####################
|
####################
|
||||||
|
|
||||||
precmd_vcs_info() { vcs_info }
|
precmd_vcs_info() { vcs_info; }
|
||||||
|
|
||||||
precmd_functions+=(precmd_vcs_info)
|
precmd_functions+=(precmd_vcs_info)
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ function +vi-git-st() {
|
|||||||
local ahead behind remote
|
local ahead behind remote
|
||||||
local -a gitstatus
|
local -a gitstatus
|
||||||
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
|
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
|
||||||
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
|
--symbolic-full-name 2>/dev/null)/refs\/remotes\//}
|
||||||
if [[ -n ${remote} ]]; then
|
if [[ -n ${remote} ]]; then
|
||||||
# for git prior to 1.7
|
# for git prior to 1.7
|
||||||
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
|
# ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
|
||||||
@@ -113,6 +113,49 @@ uv() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_uv_root() {
|
||||||
|
local target="$1"
|
||||||
|
local dir
|
||||||
|
|
||||||
|
if [[ -n "$target" && -e "$target" ]]; then
|
||||||
|
dir="$(cd "$(dirname "$target")" && pwd)"
|
||||||
|
else
|
||||||
|
dir="$PWD"
|
||||||
|
fi
|
||||||
|
|
||||||
|
while [[ "$dir" != "/" ]]; do
|
||||||
|
if [[ -f "$dir/.python-version" ]] || [[ -f "$dir/pyproject.toml" ]]; then
|
||||||
|
echo "$dir"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
dir="$(dirname "$dir")"
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
uvshim() {
|
||||||
|
local cmd="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
local uv_root=""
|
||||||
|
local first_arg="$1"
|
||||||
|
|
||||||
|
uv_root="$(find_uv_root "$first_arg")"
|
||||||
|
|
||||||
|
if [[ -n "$uv_root" ]]; then
|
||||||
|
uv run --project "$uv_root" "$cmd" "$@"
|
||||||
|
else
|
||||||
|
command -- "$cmd" "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
python() { uvshim python "$@"; }
|
||||||
|
python3() { uvshim python3 "$@"; }
|
||||||
|
pip() { uvshim pip "$@"; }
|
||||||
|
pytest() { uvshim pytest "$@"; }
|
||||||
|
|
||||||
_find_venv_upwards() {
|
_find_venv_upwards() {
|
||||||
local dir="$PWD"
|
local dir="$PWD"
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,18 @@ vipercmd="carbon" #"silicon"
|
|||||||
|
|
||||||
cd "$dir" || exit
|
cd "$dir" || exit
|
||||||
|
|
||||||
textype() { \
|
has_uv_project() {
|
||||||
|
dir="$PWD"
|
||||||
|
while [ "$dir" != "/" ]; do
|
||||||
|
if [ -f "$dir/.python-version" ] || [ -f "$dir/pyproject.toml" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
dir=$(dirname "$dir")
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
textype() {
|
||||||
command="pdflatex --shell-escape"
|
command="pdflatex --shell-escape"
|
||||||
(sed 5q "$file" | grep -i -q 'xelatex') && command="xelatex"
|
(sed 5q "$file" | grep -i -q 'xelatex') && command="xelatex"
|
||||||
$command --output-directory="$dir" "$base" &&
|
$command --output-directory="$dir" "$base" &&
|
||||||
@@ -33,7 +44,13 @@ case "$file" in
|
|||||||
*\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
|
*\.md) pandoc "$file" --pdf-engine=xelatex -o "$base".pdf ;;
|
||||||
*\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf >"$base".pdf ;;
|
*\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf >"$base".pdf ;;
|
||||||
*\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf >"$base".pdf ;;
|
*\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf >"$base".pdf ;;
|
||||||
*\.py) python3 "$file" ;;
|
*\.py)
|
||||||
|
if has_uv_project; then
|
||||||
|
uv run python "$file"
|
||||||
|
else
|
||||||
|
python3 "$file"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
*\.rmd) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;;
|
*\.rmd) echo "require(rmarkdown); render('$file')" | R -q --vanilla ;;
|
||||||
*\.sent) setsid sent "$file" 2>/dev/null & ;;
|
*\.sent) setsid sent "$file" 2>/dev/null & ;;
|
||||||
*config.h) sudo make install ;;
|
*config.h) sudo make install ;;
|
||||||
@@ -43,9 +60,9 @@ case "$file" in
|
|||||||
*\.m) octave -qW "$file" ;;
|
*\.m) octave -qW "$file" ;;
|
||||||
*\.nim) nim c -r -d:noColors "$file" ;;
|
*\.nim) nim c -r -d:noColors "$file" ;;
|
||||||
*\.r | *\.R) Rscript "$file" ;;
|
*\.r | *\.R) Rscript "$file" ;;
|
||||||
*\.rs) (cd "$dir" && cargo locate-project >/dev/null 2>&1) \
|
*\.rs) (cd "$dir" && cargo locate-project >/dev/null 2>&1) &&
|
||||||
&& (cd "$(dirname "$(cd "$dir" && cargo locate-project --message-format plain)")" && cargo run) \
|
(cd "$(dirname "$(cd "$dir" && cargo locate-project --message-format plain)")" && cargo run) ||
|
||||||
|| (rustc "$file" && "./$(basename "${file%.rs}")") ;;
|
(rustc "$file" && "./$(basename "${file%.rs}")") ;;
|
||||||
*\.sh) dash "$file" ;;
|
*\.sh) dash "$file" ;;
|
||||||
*\.smt2) z3 "$file" ;;
|
*\.smt2) z3 "$file" ;;
|
||||||
*\.tex) textype "$file" ;;
|
*\.tex) textype "$file" ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user