AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题

问题[zsh](computer)

Martin Hope
Reyhn
Asked: 2025-03-17 18:04:43 +0800 CST

zsh:将 alt+enter 绑定到行继续

  • 8

如何映射组合键alt + enter来实现行延续(不执行命令)?

我想要的最终结果如下:

> echo \
"hello"

在输入 echo 命令后,我想要按下alt+enter并让 shell 插入反斜杠和换行符,这样我就可以在下一行继续执行我的命令。

我发现这bindkey "^[^M" self-insert-unmeta会插入换行符,但不会插入反斜杠......

zsh
  • 1 个回答
  • 80 Views
Martin Hope
Hubert Kauker
Asked: 2025-01-28 02:44:52 +0800 CST

zsh 替代 while 循环意外输出

  • 8

我正在使用ZSH_VERSION=5.9并且有这个脚本,它可以按预期工作:

integer count=3
while true ; do
    echo $count
    (( count-- ))
    if (( count == 0 )) break
done
echo Finally: $count
echo ok

3它从到倒数1,然后说:Finally: 0和ok。

但是让我们do ... done用{ ... }这样的方式替换该块:

integer count=3
while true ; {
    echo $count
    (( count-- ))
    if [[ $count == 0 ]] break
}
echo Finally: $count
echo ok

绝对没有错误消息,但输出令人困惑:

3
Finally: 2
ok
2
Finally: 1
ok
1

我完全不知道为什么会这样,除非解析器有问题。还是我错误地使用了替代的 while 循环语法?当我在刚启动的 shell 中时会发生这种情况。

zsh
  • 2 个回答
  • 64 Views
Martin Hope
Cyberwiz
Asked: 2024-05-16 17:18:08 +0800 CST

如何让 zsh 自动将“..”补全为“../”

  • 5

例如,cd ..<tab>不会自动完成到cd ../

我在 macOS 上,尝试使用完全空的 .zshrc 运行。

我还尝试添加特定的compdeffor ..,但这也不起作用。

这个问题可能已经在某个地方有了答案,但很难寻找。

zsh
  • 1 个回答
  • 45 Views
Martin Hope
ekr990011
Asked: 2024-03-28 10:48:36 +0800 CST

OhMyZsh 导致 cd 推送到目录堆栈。我怎样才能将其恢复到原始状态?

  • 6

我正在使用 oh-my-zsh。启用后:

source $ZSH/oh-my-zsh.sh

该cd命令的作用类似于对所有内容进行 Pushd:

~ 
➜ dirsv
0   ~

~ 
➜ cd Projects 

~/Projects 
➜ dirsv
0   ~/Projects
1   ~

~/Projects 
➜ cd Test 

~/Projects/Test 
➜ dirsv
0   ~/Projects/Test
1   ~/Projects
2   ~

~/Projects/Test 
➜ cd ~

~ 
➜ dirsv
0   ~
1   ~/Projects/Test
2   ~/Projects

dirsv 是我自己的别名: alias dirsv="dirs -v"

我的 .zshrc 中有趣的部分是 plugins() 块被注释掉了。如果我取消注释这些插件但注释掉 source $ZSH/oh-my-zsh.sh 然后目录堆栈再次按预期工作。

我尝试过调试,但已经没有想法了。谢谢你的时间。

.zshrc 包含来自常规 cd 命令的不需要的 Pushd:

# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$HOME/.local/bin:$PATH

export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

# Path to doom emacs
export PATH=$HOME/.emacs.d/bin/:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# SSH key management for servers
# Start the ssh-agent if it is not already running
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
    eval "$(ssh-agent -s)"
fi

# Add keys to the ssh-agent if it doesn't have them already
if [[ "$(ssh-add -l)" == "The agent has no identities." ]]; then
    ssh-add ~/.ssh/id_ed25519 > /dev/null 2>&1
fi

# Dirs/pushd/popd aliases
alias dirsv="dirs -v"
alias dirsp="dirs -p"
alias dirsc="dirs -c"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# fast-syntax-highlighting 
# plugins=(git aliases zsh-vi-mode asdf zsh-autosuggestions zsh-syntax-highlighting zsh-autocomplete)
# possibly add zsh-vi-mode

# Additional configuration for autosuggestions
# ZSH_AUTOSUGGEST_STRATEGY=(history completion)
# ZSH_AUTOSUGGEST_USE_ASYNC=true

# Accept autosuggestion one word at a time
bindkey -M vicmd '^L' vi-forward-word
bindkey -M viins '^L' vi-forward-word
#

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
export LANG=en_US.UTF-8


export NVIM_APPNAME="nvim-Kickstart"
#vv() {
#  # Assumes all configs exist in directories named ~/.config/nvim-*
#  local config=$(fd --max-depth 1 --glob 'nvim-*' ~/.config | fzf --prompt="Neovim Configs > " --height=~50% --layout=reverse --border --exit-0)
 
#  # If I exit fzf without selecting a config, don't open Neovim
#  [[ -z $config ]] && echo "No config selected" && return
 
#  # Open Neovim with the selected config
#  NVIM_APPNAME=$(basename $config) nvim
#}

# export PATH=$PATH:$HOME/CompiledPrograms/nvim-linux64/bin/
# alias nvim="~/CompiledPrograms/nvim-linux64/bin/nvim"

# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
  export EDITOR='nvim'
else
  export EDITOR='nvim'
fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# alias ranger=". ranger"

fpath+=${ZDOTDIR:-~}/.zsh_functions

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

eval "$(starship init zsh)"

# . ~/.asdf/plugins/golang/set-env.zsh

export ASDF_GOLANG_MOD_VERSION_ENABLED=true
export PATH=$PATH:/home/doom/.go/bin
export GOPATH=/home/doom/go
export PATH=$PATH:/home/doom/go/bin
# export PATH=$PATH:/home/doom/Programs/zig/zig-linux-x86_64-0.12.0-dev.1344+37295696e/zig
# alias zig=/home/doom/Programs/zig/zig-linux-x86_64-0.12.0-dev.1344+37295696e/zig

# if command -v zoxide > /dev/null; then
#   eval "$(zoxide init zsh)"
# fi

# Source the Lazyman shell initialization for aliases and nvims selector
# shellcheck source=.config/nvim-Lazyman/.lazymanrc
[ -f ~/.config/nvim-Lazyman/.lazymanrc ] && source ~/.config/nvim-Lazyman/.lazymanrc
# Source the Lazyman .nvimsbind for nvims key binding
# shellcheck source=.config/nvim-Lazyman/.nvimsbind
[ -f ~/.config/nvim-Lazyman/.nvimsbind ] && source ~/.config/nvim-Lazyman/.nvimsbind
# Luarocks bin path
[ -d ${HOME}/.luarocks/bin ] && {
  export PATH="${HOME}/.luarocks/bin${PATH:+:${PATH}}"
}
# Bob neovim version manager path
[ -d ${HOME}/.local/share/bob/nvim-bin ] && {
  export PATH="${HOME}/.local/share/bob/nvim-bin${PATH:+:${PATH}}"
}

# Zoxide
# eval "$(zoxide init --cmd cd zsh)"

# Atuin command history manager
# eval "$(atuin init zsh)"

# Alias to start kmonad and store its PID in an environment variable
alias km='kmonad /home/doom/.config/kmonad/first.kbd & export KMONAD_PID=$!'

# Alias to kill kmonad using the stored PID
alias kmd='kill -SIGINT $KMONAD_PID'

[ -f "/home/doom/.ghcup/env" ] && . "/home/doom/.ghcup/env" # ghcup-env
zsh
  • 1 个回答
  • 31 Views
Martin Hope
Pelican Cyber
Asked: 2024-02-27 10:18:48 +0800 CST

当终端打开时如何默认启动 tmux 排除 Dolphin 中的终端

  • 7

我想在打开终端(例如 Yakuake、Konsole)时将 tmux 设置为默认值,但在 Dolphin 文件管理器中排除该终端。

我将以下代码片段放入~/.zshrc

if [[ -x "$(command -v tmux)" ]] && [[ -n "${DISPLAY}" ]] && [[ -z "${TMUX}" ]]; then
    windowname=$(xdotool getactivewindow getwindowname)
    if [[ ${windowname} =~ ".*Yakuake$" ]] || [[ "${windowname}" =~ ".*Konsole$" ]]; then
        exec tmux
    fi
fi

但该命令xdotool getactivewindow似乎总是得到错误的活动窗口。所以我写了这个片段来~/.zshrc进行测试。

xdotool getactivewindow && xdotool getactivewindow getwindowname
sleep 3
xdotool getactivewindow && xdotool getactivewindow getwindowname

但是当通过快捷键ctrl++打开Yakuake时,我得到如下结果。似乎获得了错误的活动窗口名称,即最后一个激活的窗口(在示例中是),它应该是 Yakuake。altYxdotoolsublimetext

94371843
~/.zshrc - Sublime Text
65011722
~ : sleep — Yakuake

当通过KDE等离子或命令行激活Yakuake或Konsole时也有同样的现象。

当终端打开时,如何将 tmux 作为默认启动排除 Dolphin 中的终端?


更新:感谢卡米尔·马乔罗夫斯基的回答,在我的~/.zshrc.

if [[ -x "$(command -v tmux)" ]] && [[ -n "${DISPLAY}" ]] && [[ -z "${TMUX}" ]]; then
    if [[ ! "$(readlink -f /proc/${PPID}/exe)" =~ "dolphin" ]]; then
        exec tmux
    fi
fi
zsh
  • 1 个回答
  • 33 Views
Martin Hope
Ferroao
Asked: 2023-09-14 06:43:29 +0800 CST

如何在 p10k 命令行中更改文件夹分隔符和 ~ 字符

  • 5

在powerlevel10k (zsh) 中,分支分隔符的路径可以是三角形或半圆形(图像底部);在 powerline (图像顶部)中,“三角形”也可以分隔文件夹/子文件夹而不是/,这在 p10k 中可以实现吗?

我使用Meslo LG S,因为它适合 p10k 图标。

在此输入图像描述

p10k 提示符的外部图像 /

编辑:要替换~为主页图标,请将其添加到.p10k.zsh

  typeset -g POWERLEVEL9K_HOME_FOLDER_ABBREVIATION=$'\uF015'
  typeset -g POWERLEVEL9K_DIR_CLASSES=()
zsh
  • 1 个回答
  • 32 Views
Martin Hope
milkpirate
Asked: 2023-09-05 22:45:15 +0800 CST

gnome-terminal 无法正确显示 UTF-8 字符 (zsh)

  • 5

我在 Ubuntu 22.04.3 上安装了 zsh v5.8.1。我的 gnome 终端看起来像这样:

在此输入图像描述

符号似乎不正确。怎么了?

zsh
  • 1 个回答
  • 13 Views
Martin Hope
Jim Worrall
Asked: 2023-08-10 08:09:56 +0800 CST

zsh:stdout 和 stderr 都用于控制台和日志

  • 6

我正在将脚本从 bash 转换为 zsh,并且已经在输出中苦苦挣扎了好几天。我希望 stdout 和 stderr 都转到控制台和日志文件。我已经尝试了网上能找到的所有方法,但没有任何乐趣。我已经阅读了 zsh 手册的重定向部分,但没有发现任何帮助,尽管我必须承认我不清楚。

以下是我在脚本开头附近尝试过的实验及其结果:

exec 2>&1 | tee -i test.log     # everything in console, log created but empty
exec 2>&1 | tee -i > test.log   # everything in console, log created but empty
exec 1>>$LOG; exec 2>&1         # everything in log, none in console
exec 2>&1; exec 1>>$LOG         # console gets errors only; log stdout only
exec &> >(tee "$LOG")           # works in bash, error in zsh
exec > >(tee -i ${LOG?}) 2>&1   # error
exec |& tee $LOG                # error
exec > >(tee $LOG) 2>&1         # error

我还尝试了解 zsh 选项 multios,但无法理解它。它应该默认打开,但当我运行时,我在选项列表中找不到它setopt。当我跑步时也没有setopt multios。当我运行时unsetopt multios,我看到了该选项nomultios,但这似乎没有帮助

我知道已经有人提出并回答了类似的问题,但答案大多在上面的列表中,对我不起作用。

我认为这不相关,但我还设置了一个获取文件描述符 3 的调试日志。它仅适用于以 >&3 结尾的调试输出行。

任何寻找此类解决方案的人请注意:上述 exec 试验是用混乱的 shebang 完成的,并且纠正后的结果有点不同。除了下面 Gairfowl 的解决方案之外,这也有效:

exec > >(tee $LOG) 2>&1
zsh
  • 1 个回答
  • 54 Views
Martin Hope
Niing
Asked: 2023-03-27 09:49:55 +0800 CST

如何在不转义 # 符号的情况下传递 zsh 字符串?

  • 5

如题。我是 zsh 的用户,我经常阅读这样的帖子:

nix profile install nixpkgs#hello

但我需要为最后一个参数添加引号以避免此错误:

zsh: no matches found: nixpkgs#hello

是否可以只使用上面的命令而不是带有的命令'nixpkgs#hello'?

zsh
  • 1 个回答
  • 20 Views
Martin Hope
Fabiano Soriani
Asked: 2022-12-14 20:24:44 +0800 CST

配置 Visual Studio Code 以从 zsh 共享相同的终端历史记录?

  • 7

我在 Mac 上同时使用 VScode 的内置终端 + 终端 (zsh)。我的印象是他们曾经共享相同的历史,但现在不再了。

理想情况下,我输入的命令会自动附加到我通常位于/Users/<my-user>/.zsh_history.

有没有一种简单的方法可以配置我的 vscode 终端以从我的 zsh 共享相同的历史记录?

zsh
  • 1 个回答
  • 63 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve