From 0f329689e66948568c999c5110116f77632afc09 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Tue, 16 Jul 2024 12:30:34 +0200 Subject: [PATCH] sync nvim and make py function better --- .config/nvim | 2 +- .zshrc | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.config/nvim b/.config/nvim index 2a6fb44..60fb779 160000 --- a/.config/nvim +++ b/.config/nvim @@ -1 +1 @@ -Subproject commit 2a6fb440abc22a21d20fb3e4166f414ec43f495a +Subproject commit 60fb779958bcc8bf09aa3ed334f2149f7fefbfa0 diff --git a/.zshrc b/.zshrc index f125b90..cb0e539 100644 --- a/.zshrc +++ b/.zshrc @@ -60,8 +60,25 @@ function condac() { } # calculate on shell with `c 1+1` function c() { printf "%s\n" "$@" | bc -l; } -# call python in a print from args -function py() { python -c "from math import *; print($*)" } +# Call Python and execute multiple statements from args +function py() { + python <<< " +from math import * + +def evaluate_and_print(code): + for expr in code.split(';'): + expr = expr.strip() + if '=' in expr: + exec(expr) + else: + result = eval(expr) + print(f\"{expr} => {result}\") + +if __name__ == \"__main__\": + expr = '$*' + evaluate_and_print(expr) +" +} ### ---- zsh options ------------------------------------- setopt autocd