In [ ]:
%lsmagic
Out[ ]:
Available line magics:
%alias  %alias_magic  %autoawait  %autocall  %automagic  %autosave  %bookmark  %cat  %cd  %clear  %colors  %conda  %config  %connect_info  %cp  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %pip  %popd  %pprint  %precision  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.
In [ ]:
%%javascript
alert('javascript');

In [ ]:
import IPython
In [ ]:
from revChatGPT.V1 import Chatbot, configure


bot = Chatbot(
    config = configure(),
    conversation_id = 'fdf52ab3-f8c1-450f-86f2-5a25d43fc48d',
    lazy_loading = True
)
In [ ]:
for response in bot.ask('''
Juypyter Lab 有没有 zsh 的 magic command?
'''):
    IPython.display.display(IPython.core.display.Markdown(response['message']))
    IPython.display.clear_output(wait=True)

JupyterLab 支持使用 ! 前缀来执行命令,类似于在终端中执行命令。如果你想使用 zsh 的 magic command,可以在单元格中使用 !zsh -c 命令来执行,例如:

!zsh -c 'echo hello world'

这将会使用 zsh 来执行 echo hello world 命令。

In [ ]:
for response in bot.ask('''
Juypyter Lab 中 zsh 的 magic command 没有加载 ~/.zshrc,该怎么办呢?
'''):
    IPython.display.display(IPython.core.display.Markdown(response['message']))
    IPython.display.clear_output(wait=True)

在 Jupyter Lab 中加载 zsh 的 magic command 时,如果发现没有加载 ~/.zshrc 中的内容,可以尝试在 ~/.zshenv 中添加以下内容:

# Load user's ~/.zshrc, but in non-interactive shell environments.
if [[ -n "$ZSH_VERSION" ]]; then
  if [[ -e "$HOME/.zshrc" ]]; then
    source "$HOME/.zshrc"
  fi
fi

这样在 Jupyter Lab 中执行 zsh 的 magic command 时,应该就能加载 ~/.zshrc 中的内容了。

In [ ]:
%%bash
cat << EOF >> ~/.zshenv

# Load \`nvm\` in non-interactive shell environments.
if [[ -n "$NVM_DIR" ]]; then
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
fi
EOF
In [ ]:
!zsh -c 'cat ~/.zshenv'
. "$HOME/.cargo/env"

# Load `nvm` in non-interactive shell environments.
if [[ -n "/Users/saintway/.nvm" ]]; then
    export NVM_DIR="/Users/saintway/.nvm"
    [ -s "/Users/saintway/.nvm/nvm.sh" ] && \. "/Users/saintway/.nvm/nvm.sh"
fi
In [ ]:
!zsh -c 'nvm ls'
    iojs-v1.0.4
->      v19.7.0
         system
default -> node (-> v19.7.0)
unstable -> N/A (default)
node -> stable (-> v19.7.0) (default)
stable -> 19.7 (-> v19.7.0) (default)
iojs -> iojs-v1.0 (-> iojs-v1.0.4) (default)
lts/* -> lts/hydrogen (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.19.1 (-> N/A)
lts/hydrogen -> v18.15.0 (-> N/A)

Comments

2023-03-13