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"
  },
  //...
]

参考资料

相关推荐
海域云SeaArea_6 分钟前
Windows Server 2008 R2 从零安装 IIS7.5(二):php.ini 配置
开发语言·windows·php
IsITGirl4 小时前
VMware Fusion(Mac)Windows ARM 虚拟机 NAT (vmnet8) 报错解决记录
windows·macos·.net·桥接模式
Rudon滨海渔村4 小时前
台式机Win10实现“音量+”和“音量-”,键盘映射方案
windows·计算机外设·powertoys
2501_915921434 小时前
KXBuild CI 实操,Windows/Linux 服务器接入 Jenkins 打包 iOS IPA
服务器·windows·vscode·ios·ci/cd·个人开发·敏捷流程
谙弆悕博士5 小时前
debian快速换源
linux·运维·windows·debian·下载·换源·网络问题
?re?ta?rd?ed?21 小时前
C++11新特性,{}与左值
c++·windows
必须得开心呀1 天前
windows10系统任务栏图标消失修复
windows
zl_dfq1 天前
Windows 下 UDP 套接字编程指南
网络·windows·udp
学习论之费曼学习法1 天前
无人值守AI内容矩阵实战(10):Windows 上让 Python 进程 7×24 活着
人工智能·windows·python·矩阵·powershell·进程守护
少年的范儿1 天前
Windows 安装 MySQL 8.4 教程(ZIP 解压版):配置 my.ini、初始化数据库与启动服务
数据库·windows·mysql