找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 259|回复: 0

MacOS上使用oh-my-zsh

[复制链接]
发表于 2024-7-16 14:55:18 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
本帖最后由 lichao 于 2024-7-17 16:54 编辑

简介

  ZSH是一款常用的命令行工具,也是MacOS默认shell。ohmyzsh是基于zsh的开源项目https://github.com/ohmyzsh/ohmyzsh,提供了一系列命令行主题及插件。可以让命令行更炫酷。笔者第一次使用ohmyzsh是在18年,从同事那里看到的,最近又想起来就玩了玩。oh-my-zsh支持的操作系统包括 Android/FreeBSD/Linux/MacOS/WSL2
agnoster.jpg    

  在ZSH的众多主题中,ohmyzsh的agnoster主题和Powerlevel10k是最火的2款,Powerlevel10k也是个开源项目https://github.com/romkatv/powerlevel10k
powerlevel10k.png

安装

   agnoster主题安装过程

  • 安装ZSH并设为默认shell. (MacOS自带)
  • 参考项目说明安装ohmyzsh. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  • ~/.zshrc中设置ZSH_THEME="agnoster"
  • 安装字体https://github.com/powerline/fonts(agnoster需要Meslo系字体才能正常显示,否则会有乱码)
  • 自带终端和iTerm2中设置字体为Meslo,然后配置配色

   Powerlevel10k主题安装

  • 参考项目说明安装Meslo LGS NF字体
  • 安装Powerlevel10k. git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
  • ~/.zshrc中设置ZSH_THEME="powerlevel10k/powerlevel10k"
  • 新建shell窗口按提示继续配置

  最终笔者配置效果如图
截屏2024-07-16 14.56.02.png

ohmyzsh主题大全

  ohmyzsh包含100多个内置提示符样式,笔者写了个脚本来展示所有主题

import os
import sys
import time
import pyautogui
from AppKit import NSWorkspace
from Quartz import (
    CGWindowListCopyWindowInfo,
    kCGWindowListOptionOnScreenOnly,
    kCGNullWindowID
)

def find_window_by(title=None, owner=None):
    curr_app = NSWorkspace.sharedWorkspace().frontmostApplication()
    curr_pid = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationProcessIdentifier']
    curr_app_name = curr_app.localizedName()
    options = kCGWindowListOptionOnScreenOnly
    windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID)
    for window in windowList:
        pid_ = window['kCGWindowOwnerPID']
        owner_ = window['kCGWindowOwnerName'].UTF8String().decode()
        bounds_ = window['kCGWindowBounds']
        title_ = window.get('kCGWindowName', b"")
        wind_info = {
            "pid": pid_,
            "owner": owner_,
            "bounds": {
                "h": int(bounds_["Height"]),
                "w": int(bounds_["Width"]),
                "x": int(bounds_["X"]),
                "y": int(bounds_["Y"]),
            },
            "title": title_,
        }
        if owner and owner == owner_:
            return wind_info
        if title and title == title_:
            return wind_info
    return None

if __name__ == "__main__":
    theme_path = os.path.expanduser("~/.oh-my-zsh/themes")
    #terminal_path = "/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal"
    terminal_path = "/Applications/iTerm.app/Contents/MacOS/iTerm2"
    index = 1
    for name in os.listdir(theme_path):
        theme = name.split(".")[0]
        img_path = "/tmp/theme/{}.png".format(index)
        if os.path.exists(img_path):
            print("pass {}".format(theme))
        else:
            os.system("export ZSH_THEME={};{} {}&".format(theme, terminal_path, theme_path))
            wind_info = None
            time.sleep(5)
            for i in range(6):
                wind_info = find_window_by("", "iTerm2") # 终端
                if wind_info:
                    break
                time.sleep(1)
            if not wind_info:
                print("err handle {}".format(theme))
                continue
            bounds = wind_info["bounds"]
            top_bar_height = 45
            content_width = 570
            content_height = 70
            shot_range = [bounds["x"], bounds["y"] + top_bar_height, content_width, content_height]
            im = pyautogui.screenshot(region=shot_range)
            im.save(img_path)
            os.kill(wind_info["pid"], 9)
            wind_info = find_window_by("-zsh")
            if wind_info:
                os.kill(wind_info["pid"], 9)
        index += 1

# convert -append *.png all.png

out-0.png
out-1.png

回复

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-9-8 09:33 , Processed in 0.041868 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表