V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
这是一个专门讨论 idea 的地方。

每个人的时间,资源是有限的,有的时候你或许能够想到很多 idea,但是由于现实的限制,却并不是所有的 idea 都能够成为现实。

那这个时候,不妨可以把那些 idea 分享出来,启发别人。
zzerd
V2EX  ›  奇思妙想

使用 espanso + gist 来管理 llm promat

  •  
  •   zzerd · 14 天前 · 1199 次点击

    因为 espanso 可以调用 shell 脚本所以约等于一个小号的 raycast 。espanso 只是一个文本扩展器软件,它有个搜索框很方便,我日常使用它来记住一些比较常用的 shell 命令,代码片段,这只是它的特别用法。

    1.先决条件安装 gh 并 Auth ,安装 espanso

    brew install gh espanso
    gh auth login
    
    

    2.在 espanso 配置目录下新建一个配置文件(~/Library/Application Support/espanso/match/promats.yml)

    
    # how to use this config 
    ## 1. install gh in your system run gh auth
    ## 2. set editor in gh  eg: gh config set editor "zed -w"  ps: you can use vscode "code -w  --disable-extensions" 
    ## 3. $: echo hello | run gh gist create  -d "llm prompt"
    ## 4. get your and change your gist id $: gh gist ls --filter prompt  
    global_vars:
      - name: gist_id 
        type: echo
        params:
          echo: b94d3e90a752b849757d2a078fbf293a
          #echo: f3171d580fab61b8a3ec76d9514863f6  # test
      # 1. Get the gist list
      - name: gist_list
        type: shell 
        params:
          cmd: "gh gist view {{gist_id}} --files"
    
      # 2. Format the list for the choice menu
      - name: gist_options
        type: shell 
        params:
          cmd: |
              echo "{{gist_list}}" | while read -r line; do
                echo "$line"
              done
    
    matches:
      - trigger: ":prompt-view"
        label: "Select LLM prompt from GitHub Gist"
        replace: "{{prompt}}"
        search_terms:
          - prompt
          - llm
          - ai
        vars:
          # 3. Show the choice menu to the user
          - name: gist_choice
            type: choice
            params:
              values: "{{gist_options}}"
    
          # 4. Get the content of the chosen gist
          - name: prompt
            type: shell 
            params:
              cmd:  gh gist view "{{gist_id}}" -r -f "{{gist_choice}}"
    
      - trigger: ":prompt-edit"
        label: "edit LLM prompt to GitHub Gist"
        replace: "{{output}}"
        search_terms:
          - prompt
          - llm
          - ai
          - edit 
        vars:
          # 3. Show the choice menu to the user
          - name: gist_choice
            type: choice
            params:
              values: "{{gist_options}}"
    
          # 4. Get the content of the chosen gist
          - name: output 
            type: shell 
            params:
              cmd:  gh gist edit "{{gist_id}}"  -f "{{gist_choice}}"
      - trigger: ":prompt-add"
        label: "add LLM prompt to GitHub Gist"
        replace: "{{output}}"
        search_terms:
          - prompt
          - llm
          - ai
          - add
        vars:
          - name: file 
            type: form
            params:
              layout: | 
                请输入文件名[[name]] 示例: claude_user#role#coding#claude
                请输入 prompt 内容:
                [[content]]
              fields:
                content:
                  multiline: true
          - name: carete_file_in_tmp 
            type: shell
            params:
              cmd: echo "{{file.content}}" > /tmp/prompt
          - name: add 
            type: shell 
            params:
              cmd:   gh gist edit "{{gist_id}}"  -a  "{{file.name}}"  /tmp/prompt
          - name: output
            type: shell 
            params: 
              cmd: gh gist view "{{gist_id}}" --files | grep "{{file.name}}" && echo "{{file.name}} create faild"  || echo "file {{file.name}} create success" 
              trim: false
                
      - trigger: ":prompt-del"
        label: "del LLM prompt for GitHub Gist"
        replace: "{{output}}"
        search_terms:
          - prompt
          - llm
          - ai
          - del 
        vars:
          # 3. Show the choice menu to the user
          - name: gist_choice
            type: choice
            params:
              values: "{{gist_options}}"
    
          # 4. Get the content of the chosen gist
          - name: delete 
            type: shell 
            params:
              cmd:  gh gist edit "{{gist_id}}"  -r "{{gist_choice}}"
          - name: output
            type: shell 
            params: 
              cmd: gh gist view "{{gist_id}}" --files | grep "{{gist_choice}}" && echo "{{gist_choice}} is delete" || echo "file {{gist_choice}} is exist" 
              trim: false
    
    
    

    3.修改 gist_id 为你自己的 gist id.文件名最好能能清晰的看出这个 promat 是干什么的比如#coding#unix_sytle

    4.其实这个配置文件只是能用,我用的并不是很多所以没有加缓存。也可以在本地把 gist clone 下来这样会快一些,在 cde 的时候同步就行,改下 shell 命令的事很简单。

    为什么使用 espanso 不写一个 raycast 就是因为这个搞起来速度快,不超过 20 分钟就搞好了改起来也快,raycast 搞这个有点费事。

    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2464 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 05:24 · PVG 13:24 · LAX 21:24 · JFK 00:24
    ♥ Do have faith in what you're doing.