随机从列表或文件中选择 “oh my posh” 主题。

huangapple go评论57阅读模式
英文:

Randomly choose between oh my posh themes from a list or file

问题

我已选择了一些主题,并将它们的名称保存在一个文件中,但我不想从所有主题中随机选择,而是想从我的自定义列表中选择,该列表保存在一个文本文件中(不是CSV,只是一个文本文件)。

在配置文件中,输入以下内容以实现这一目标:

$Profile exists with values
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression
Import-Module -Name Terminal-Icons

或者如何在Power Automate中自动完成此任务?

我还想在命令提示符(cmd)中执行相同的操作。

我的文本文件中包含以下值:

catppuccin.omp.json
clean-detailed.omp.json
cloud-native-azure.omp.json
dracula.omp.json
hul10.omp.json
hunk.omp.json
if_tea.omp.json
jandedobbeleer.omp.json
M365Princess.omp.json
sonicboom_dark.omp.json

该文件位于~/Documents/my themes.txt

英文:

I have chosen a few themes and saves their names in a file but I don't want to randomly choose from all the themes, rather choose from my own list which is saved in a text file (not a csv, just a text file).

$Profile exists with values

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression
Import-Module -Name Terminal-Icons

What to type in the profile to achieve this?
Or how can this task be automated in power automate?

I also want to do the same for command prompt (cmd).

values in my text file

catppuccin.omp.json
clean-detailed.omp.json
cloud-native-azure.omp.json
dracula.omp.json
hul10.omp.json
hunk.omp.json
if_tea.omp.json
jandedobbeleer.omp.json
M365Princess.omp.json
sonicboom_dark.omp.json

the file is located in ~/Documents/my themes.txt

答案1

得分: 2

创建一个名为 themes.txt 的文件,其中包含你想要的主题名称:

amro
wholespace
kushal
catppuccin_latte
# ... 在这里添加更多主题

将以下内容添加到你的 Microsoft.Powershell_profile.ps1 文件:

# 选择一个随机的 Oh My Posh 主题
$themes = Get-Content -Path "/path/to/themes.txt"
$selected_theme = $themes | Get-Random
$base_url = "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/"
$terminal_theme_url = "${base_url}${selected_theme}.omp.json"

# 将随机主题设置为环境变量
Set-Item -Path Env:TERMINAL_THEME -Value $terminal_theme_url

# 在终端会话启动时打印主题名称
echo "Oh My Posh 主题: $selected_theme"

oh-my-posh init pwsh --config $env:TERMINAL_THEME | Invoke-Expression
英文:

Create a file called themes.txt containing the names of the themes you'd like:

amro
wholespace
kushal
catppuccin_latte
# ... add more themes here

Add the following to your Microsoft.Powershell_profile.ps1 file:

# Select a random Oh My Posh theme
$themes = Get-Content -Path "/path/to/themes.txt"
$selected_theme = $themes | Get-Random
$base_url = "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/"
$terminal_theme_url = "${base_url}${selected_theme}.omp.json"

# Set the random theme to an environment variable
Set-Item -Path Env:TERMINAL_THEME -Value $terminal_theme_url

# Print the theme name when your terminal session starts
echo "Oh My Posh Theme: $selected_theme"

oh-my-posh init pwsh --config $env:TERMINAL_THEME | Invoke-Expression

答案2

得分: 0

这不是完整答案,但我无法格式化评论,所以这是 PowerShell 脚本的答案:

Import-Module -Name Terminal-Icons
$random_theme = Get-Content "C:\Users\Jawad11\Documents\my themes.txt" | Get-Random
echo $random_theme.name
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH$random_theme" | Invoke-Expression
英文:

This is not the complete answer, but I can't format the comments so here goes the answer to powershell script.

Import-Module -Name Terminal-Icons
$random_theme = Get-Content "C:\Users\Jawad11\Documents\my themes.txt" | Get-Random
echo $random_theme.name
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH$random_theme" | Invoke-Expression

huangapple
  • 本文由 发表于 2023年2月23日 19:48:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定