Windows也能拥有好用的命令行吗?Powershell+Terminal折腾记录(v1.0版本)

PS:本文写于2021年,现在已经是2024年,有了很多新变化,我在接下来的文章里会继续更新。

前言

Windows一向以图形化操作入门容易著称,所以对于命令行的支持一直为人所诟病,比起Linux或者mac都是被吊打的。这一局面在最近几个版本的Windows10更新里,特别是微软官方出了WindowsTerminal这个大杀器之后有所改善~

所以对于标题的这个问题,只能说「勉强可以吧」,本文介绍几个折腾命令行的方法。

效果图

偷一张官方的截图,应该没人发现吧

建议先熟读官方文档:https://docs.microsoft.com/zh-cn/windows/terminal/

软件包管理器 Scoop

不用羡慕Linux上好用的apt和yum,Windows上也有不错的软件包管理器,比如chocolate、官方的win-get,还有本文介绍的scoop,相比起chocol ate,scoop的软件包仓库都是社区维护开源的,安全性更有保障,并且比官方的win-get多很多~ 不够可以自己添加软件源,就像apt的PPA源。

官网:https://scoop.sh/

安装:

复制代码
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex

oh-my-posh & powerline

用过oh-my-zsh的同学就知道这个oh-my-xxx的项目了~ Windows上自然不能少~

地址: https://ohmyposh.dev/docs/

首先下载powerline字体并安装,These fonts can be installed from the Cascadia Code GitHub releases page.

输入命令安装powershell插件,post-git需要git支持,If you don't already have it, install Git for Windows.

复制代码
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser

Open your PowerShell profile with notepad $PROFILE,输入以下内容:

复制代码
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

打开terminal配置,修改字体,for example:

json 复制代码
{
    // Make changes here to the powershell.exe profile.
    "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "name": "Windows PowerShell",
    "commandline": "powershell.exe",
    "fontFace": "Cascadia Code PL",
    "hidden": false
},

配置完的效果:

参考资料:https://docs.microsoft.com/en-us/windows/terminal/tutorials/powerline-setup

使用sudo(gsudo)

在用Windows的powershell的时候,有时一些操作是需要管理员权限的,但是不像Linux那么方便,一句sudo命令即可提权,Windows往往需要右键点击开始菜单,选择powershell的管理员模式。

麻烦不说,还可能导致心急的同学砸键盘

不过办法总比困难多,这不有了开源的gsudo,可以在Windows方便提权,安装方法如下~

安装:

复制代码
PowerShell -Command "Set-ExecutionPolicy RemoteSigned -scope Process; iwr -useb https://raw.githubusercontent.com/gerardog/gsudo/master/installgsudo.ps1 | iex"

装完就可以直接在powershell里使用sudo命令提权了,同时可以在Terminal里添加一个管理员权限的标签卡,看看怎么配置

在terminal的配置文件中添加一项:

json 复制代码
"list": [
  {
      "guid": "{41dd7a51-f0e1-4420-a2ec-1a7130b7e950}",
      "name": "Windows PowerShell Elevated",
      "commandline": "gsudo.exe powershell.exe",
      "hidden": false,
      "colorScheme": "Solarized Dark",
      "fontFace": "Fira Code",
      "icon" : "https://i.imgur.com/Giuj3FT.png"
  },
  //...
]

参考资料

相关推荐
武藤一雄16 小时前
C# 关于多线程如何实现需要注意的问题(持续更新)
windows·后端·microsoft·c#·.net·.netcore·死锁
coding消烦员20 小时前
在 Windows 内网搭建 Git 仓库:共享普通仓库 vs 中心 bare 仓库
windows·git
xiaoliuliu123451 天前
IE8-WindowsXP-x86-CHS_23253_BDdl.exe 安装步骤(XP 32位简体中文版)
windows
百事牛科技1 天前
文件不想再加密了?取消Word 打开密码的方法
windows·word
love530love1 天前
EPGF 新手教程 13在 PyCharm(中文版 GUI)中创建 Hatch 项目环境,并把 Hatch 做成“项目自包含”(工具本地化为必做环节)
开发语言·ide·人工智能·windows·python·pycharm·hatch
峰上踏雪1 天前
Go(Golang)Windows 环境配置关键点总结
开发语言·windows·golang·go语言
lusasky1 天前
在Windows上编译、安装Rust
开发语言·windows·rust
麻辣长颈鹿Sir1 天前
CMAKE指令集
linux·运维·windows·cmake·cmake指令集
Alice10291 天前
如何在windows本地打包python镜像
开发语言·windows·python
北京流年1 天前
windows安装jenkins并且编译app
运维·windows·jenkins