• 请不要在回答技术问题时复制粘贴 AI 生成的内容
as9567585
V2EX  ›  程序员

有熟悉 iTerm2 的朋友吗,怎么能获取到变量 profile.name

  •  
  •   as9567585 · Dec 8, 2022 · 1439 views
    This topic created in 1250 days ago, the information mentioned may be changed or developed.

    怎么能获取到${profile.name}呢?

    img

    有一个脚本需要用到

    写了一个脚本可以,自动打开远程文件,自动同步。

    这样就用不手动 scp ,或者打开其他 sftp 工具了。只要

    ./sedit.py user@host:/path/file.ext
    

    或者自定义编辑器

    ./sedit.py user@host:/path/file.ext [code/subl/...]
    

    希望可以直接右键编辑

    因为我的 profile.name 都是配置的和.ssh/config 里的 Host 是一样的,密钥也是配置好的。 所以只要拿到 profile.name 就可以配合之前的脚本直接编辑了。

    img

    7 replies    2022-12-09 12:55:35 +08:00
    slowman
        1
    slowman  
       Dec 8, 2022
    env ITERM_PROFILE
    我是如何知道的? env 看到了
    as9567585
        2
    as9567585  
    OP
       Dec 9, 2022
    @1423 囧,还是不会用,再帮忙看看呗,这里要怎么写呢? 我这样写还是获取不到
    as9567585
        3
    as9567585  
    OP
       Dec 9, 2022
    @1423 本地终端可以打印出来,ssh 到远程就打印不出来了,还是不是知道 Parameter 里怎么写可以获取到
    slowman
        4
    slowman  
       Dec 9, 2022
    @as9567585 我想你应该考虑的是 iTerm2 的 Run Command 的执行机制,iTerm2 传递了哪些 env 给新环境。
    试一下就发现,ITERM_PROFILE 不在其中
    as9567585
        5
    as9567585  
    OP
       Dec 9, 2022
    @1423 😂 有啥办法吗
    Kobayashi
        6
    Kobayashi  
       Dec 9, 2022 via Android
    处于安全考虑,ssh 服务端对传递的环境变量有限制。man sshd_config, AcceptEnv.

    某些 distro 开了个口子,默认额外允许接收 LC_ 前缀环境变量。如果你修改不了 sshd 服务端配置,可以试着走这个方案。
    as9567585
        7
    as9567585  
    OP
       Dec 9, 2022
    @Kobayashi 必须通过服务端吗?能不能直接通过 iTerm 获取这个变量,毕竟这也是在 iTerm 的 context 中
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4830 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 10:05 · PVG 18:05 · LAX 03:05 · JFK 06:05
    ♥ Do have faith in what you're doing.