UoE BSc Computer Science First-class Honours --> Imperial MSc Advanced Comput'ing
使用echo $PROFILE
查看你的Windows Terminal使用的是哪个 profile.ps1
文件
. $PROFILE
来像 source ~/.bashrc
一样让你的改动生效,或重启终端export xxx=xxxxxx
):Set-Variable -Name “xxx” -Value “xxxxxxx” -Option Constant
$xxx = xxxxxx
alias f="xxxx"
):function f { xxxx }
function proj {
param (
[string]$projName,
[switch]$vscode,
[switch]$explorer
)
if ($projName) {
$projPath = Join-Path -Path $funpy -ChildPath $projName
if (Test-Path $projPath) {
Set-Location $projPath
if ($explorer) {
explorer.exe .
}
if ($vscode -or -not $explorer) {
code .
}
} else {
Write-Error "The project '$projName' does not exist."
}
} else {
Get-ChildItem -Path $funpy -Directory | ForEach-Object { $_.Name }
}
}
https://stackoverflow.com/questions/15694338/how-to-get-a-list-of-custom-powershell-functions:
# get custom functions
$sysfunctions = Get-ChildItem function:
function custom {Get-ChildItem function: | Where-Object {$sysfunctions -notcontains $_} }
profile.ps1
的文档,比如 readme.md
编写以下简单streamlit网页简单粗暴的读取md并展示
import streamlit as st
import os
import subprocess
# Set the page configuration to use the wide layout
st.set_page_config(layout="centered")
# Retrieve the profilePath variable from PowerShell
# 确保你在环境变量里或profile.ps1里定义了profilePath路径,也就是你的$PROFILE住的文件夹
profile_path = subprocess.check_output(['powershell', '-Command', '(Get-Variable -Name profilePath).Value'], text=True).strip()
doc_path = os.path.join(profile_path, 'readme.md')
with open(doc_path, 'r', encoding='utf-8') as file:
readme_content = file.read()
st.markdown(readme_content)
以及定义一个简单的function来取代手打指令
function doc {
$doc_py_path = Join-Path -Path $profilePath -ChildPath "doc.py"
streamlit run $doc_py_path
}
doc
在命令行里,就获得: