diff options
author | Vikas Kushwaha <dev@vikas.rocks> | 2025-01-24 10:35:59 +0530 |
---|---|---|
committer | Vikas Kushwaha <dev@vikas.rocks> | 2025-01-24 10:35:59 +0530 |
commit | 18507fd21b7a7709133d8f3049c683e1abffcda2 (patch) | |
tree | d43bc141b2e588300e639bdb4f004ad6945e6081 /.local/bin | |
parent | e02304f014645a01ef6cdd40276997dea58504d9 (diff) |
jupyter update
Diffstat (limited to '.local/bin')
-rwxr-xr-x | .local/bin/desktop/show-i3-keybindings | 2 | ||||
-rwxr-xr-x | .local/bin/development/dev | 7 | ||||
-rwxr-xr-x | .local/bin/development/gitpush | 5 | ||||
-rwxr-xr-x | .local/bin/development/ipy | 6 | ||||
-rwxr-xr-x | .local/bin/development/jp | 16 | ||||
-rwxr-xr-x | .local/bin/development/jpconvert | 16 | ||||
-rwxr-xr-x | .local/bin/development/pyh | 2 | ||||
-rwxr-xr-x | .local/bin/fmd | 11 | ||||
-rwxr-xr-x | .local/bin/fw | 9 | ||||
-rwxr-xr-x | .local/bin/preview | 6 |
10 files changed, 56 insertions, 24 deletions
diff --git a/.local/bin/desktop/show-i3-keybindings b/.local/bin/desktop/show-i3-keybindings index 45d0626..f7d7d70 100755 --- a/.local/bin/desktop/show-i3-keybindings +++ b/.local/bin/desktop/show-i3-keybindings @@ -6,6 +6,6 @@ if [ -n "$TERM" ]; then column --table --separator='|' | less -r else grep '^bindsym' ~/.config/i3/config | sort | - sed 's/^bindsym \(\S*\)\s\+\(.*\)$/\1|\2/; s/\$super+/ /; s/Shift+/Shift /; s/$alt+/Alt /; s/Ctrl+/Ctrl /' | + sed 's/^bindsym \(\S*\)\s\+\(.*\)$/\1|\2/; s/\$super+/ /; s/Shift+/⬆️ /; s/$alt+/⎇ /; s/Ctrl+/Ctrl /' | column --table --separator='|' | yad --text-info fi diff --git a/.local/bin/development/dev b/.local/bin/development/dev index bcb5b46..cd95f27 100755 --- a/.local/bin/development/dev +++ b/.local/bin/development/dev @@ -49,8 +49,8 @@ go_format() { gofmt "$file"; } go_lint() { gofmt -d "$file"; } go_compile() { go build "$file"; } go_run() { "$(realpath "${file%.go}")" "$@"; } -go_test() { go run "$file" "$@"; } -go_serve() { findweb . -name '*.go' | entr -r sh -c "printf '\n\n$ go run *.go\n'; go run *.go"; } +go_test() { TMPDIR=~/.cache/go-tmp go run "$file" "$@"; } +go_serve() { findweb . -name '*.go' | entr -r sh -c "printf '\n\n$ go run *.go\n'; dev test *.go"; } c_test() { out="${file%.c}" @@ -110,6 +110,9 @@ kt_test() { rm "$out" } +py_format() { autopep8 "$file"; } +py_formatin() { autopep8 -i "$file"; } + py_serve() { findweb . -name '*.py' | entr -r python "$file"; } # py_lint() { # [ -t 1 ] && printf '\033[33m' diff --git a/.local/bin/development/gitpush b/.local/bin/development/gitpush index 0af8e20..7774a7b 100755 --- a/.local/bin/development/gitpush +++ b/.local/bin/development/gitpush @@ -8,13 +8,12 @@ push_to_remote() { esac git add --all - git commit - git push -u origin + git commit && git push -u origin } [ -z "$1" ] && { push_to_remote; exit; } for dir in "$@"; do - cd "$dir" || exit 1 + cd "$dir" || exit push_to_remote done diff --git a/.local/bin/development/ipy b/.local/bin/development/ipy index 1f39550..ae26eb1 100755 --- a/.local/bin/development/ipy +++ b/.local/bin/development/ipy @@ -1,4 +1,8 @@ #!/bin/sh unset PYTHONSTARTUP -"${XDG_DATA_HOME:-$HOME/.local/share}/virtualenvs/main/bin/ipython" "$@" + +env="${XDG_DATA_HOME:-$HOME/.local/share}/virtualenvs/main/bin/activate" +[ -f "$env" ] && . "$env" + +ipython "$@" diff --git a/.local/bin/development/jp b/.local/bin/development/jp new file mode 100755 index 0000000..19bf0bc --- /dev/null +++ b/.local/bin/development/jp @@ -0,0 +1,16 @@ +#!/bin/sh + +# Alias to jupyter. +# Select and launch console when no arguments are passed. + +[ -f "${XDG_DATA_HOME:=$HOME/.local/share}/virtualenvs/main/bin/activate" ] && + . "$XDG_DATA_HOME/virtualenvs/main/bin/activate" + +[ "$#" -eq 0 ] && { + kernel="$(find "$XDG_DATA_HOME/jupyter/runtime" -name 'kernel*' -printf '%TY-%Tm-%Td %TH:%TM:%.2TS %f\n' | + sed 's/kernel-\(.\+\)-.\+-.\+-.\+-.\+\.json/\1/' | sort --reverse | + fzf --header="Select jupyter kernel" --header-first | cut -d\ -f3)" || exit + set -- console --existing "$kernel" +} + +jupyter "$@" diff --git a/.local/bin/development/jpconvert b/.local/bin/development/jpconvert new file mode 100755 index 0000000..0fa3bbc --- /dev/null +++ b/.local/bin/development/jpconvert @@ -0,0 +1,16 @@ +#!/bin/sh + +env="${XDG_DATA_HOME:-$HOME/.local/share}/virtualenvs/main/bin/activate" +[ -f "$env" ] && . "$env" + +notebook="$1" +script="${notebook%.ipynb}.py" +jupyter nbconvert --to script "$notebook" + +sed -i \ + -e "s/^# coding: .*$/# same as $notebook/" \ + -e "s/^\([A-Za-z0-9_.]\+\)$/print(\"\\\nData in '\1' :-\", \1, sep='\\\n', end='\\\n\\\n')/" \ + "$script" + +sed -i -z "s/\n# In\[[0-9 ]*\]:\n\n//g" "$script" +sed -i -z "s/\n\s*\n\([][A-Za-z0-9_\.(,)]\+\)\n\n\n/\nprint(\"\\\n>>> \1\", \1, sep='\\\n', end='\\\n\\\n')\n\n\n/g" "$script" diff --git a/.local/bin/development/pyh b/.local/bin/development/pyh index fdd524a..d8bd1a4 100755 --- a/.local/bin/development/pyh +++ b/.local/bin/development/pyh @@ -5,6 +5,8 @@ [ -x "${XDG_DATA_HOME:-$HOME/.local/share}/virtualenvs/main/bin/python" ] && alias python="${XDG_DATA_HOME:-$HOME/.local/share}/virtualenvs/main/bin/python" +export PAGER="less $LESS" + if [ "$#" -gt 0 ]; then python -c "help('$*')" else diff --git a/.local/bin/fmd b/.local/bin/fmd index 0139d77..72e5542 100755 --- a/.local/bin/fmd +++ b/.local/bin/fmd @@ -6,16 +6,7 @@ export PREVIEW="${PREVIEW:-"cat \"\$(dirname {})/.description/\${\$(basename {})%.*}.txt\" 2>/dev/null || preview {}"}" -find "$@" -type f \ - ! -path '*/.*' \ - ! -name '*.srt' \ - ! -name '*.vtt' \ - ! -name '*.description' \ - ! -wholename '.description/*' \ - ! -name '*.info.json' \ - ! -name '*.live_chat.json' \ - ! -name '*.yt*' | - sort | +fd -I --color=always --type=file --ignore-file="${XDG_CONFIG_HOME:-$HOME/.config}/ytignore" "$@" | sort | fzf --multi --reverse \ --history="${FZF_HIST:=$HOME/.local/share/fzf/media_history}" \ --header="${FZF_HEADER:-Browse Media Files}" --header-first \ diff --git a/.local/bin/fw b/.local/bin/fw index ada20e8..75f23af 100755 --- a/.local/bin/fw +++ b/.local/bin/fw @@ -1,10 +1,11 @@ #!/bin/sh -export FZF_HIST="$HOME/.local/share/fzf/wiki_history" +export FZF_HIST="${XDG_DATA_HOME:-$HOME/.local/share}/fzf/wiki_history" export FZF_HEADER="Search local wiki files" -export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --delimiter='/' --with-nth=-1" -fmd \ +export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --delimiter='/' --with-nth=-3.." +fmd . \ /mnt/storage/Media/Tech/ \ /mnt/storage/Library \ /usr/share/doc/arch-wiki/html/en \ - "$@" ! -name '*.css' + --exclude '*.css' \ + "$@" diff --git a/.local/bin/preview b/.local/bin/preview index 2968843..b71d0f0 100755 --- a/.local/bin/preview +++ b/.local/bin/preview @@ -2,9 +2,9 @@ if [ -d "$1" ]; then if [ -x /bin/eza ] || [ -x /usr/bin/eza ]; then - eza -alhF --group-directories-first --color=always --icons -- "$1" + eza -alhF --group-directories-first --color=always --icons=always -- "$1" else - ls -lhAF --group-directories-first --color -- "$1" + ls -lhAF --group-directories-first --color=always -- "$1" fi readme="$(find "$1" -maxdepth 1 -name "README.*" | head -1)" [ -n "$readme" ] && preview "$readme" @@ -14,7 +14,7 @@ fi alias highlight='highlight --out-format=ansi' case "$1" in - '') echo "preview: file name required" >&2; exit 1 ;; + '') echo "USAGE: preview <FILE>" >&2; exit 1 ;; *.html) w3m -dump "$1" ;; *.md) glow -s dark --width="${FZF_PREVIEW_COLUMNS:-"$(tput cols)"}" "$1" ;; # *.vim) highlight --syntax=vim --replace-tabs=2 -- "$1" ;; |