【Windows】【Mac】powershell 和 bash 别名

目录

一. 问题

二. Windows Alias

三. Mac Alias

3.1 tools

四. 参考


一. 问题

        最近切换电脑, 调试问题输入命令,各个平台上输的手疼,想着有别名来代替简输的方式; 后续我就可以输入一些简短缩写来执行命令了,省去了不少调试和手工输入时间;

二. Windows Alias

1. 执行如下命令:

PS C:\Users\xxx> $profile
C:\Users\xxx\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

2. 在C:\Users\xxx\Documents\WindowsPowerShell\ 目录下,新建Microsoft.PowerShell_profile.ps1 文件 

输入如下命令:

FUNCTION local { git config --local --list }
FUNCTION global { git config --global --list }
FUNCTION gk { gitk --all --date-order }
FUNCTION pull { git pull origin }
FUNCTION push { git push origin }
FUNCTION prune { git remote prune origin }
FUNCTION hf { gitk HEAD..FETCH_HEAD }
FUNCTION dhf { gitk HEAD...FETCH_HEAD }
FUNCTION tag { git tag --list }
Function pypath { python -c "import sys, json;print(json.dumps(sys.path, indent=4))" }

重启 PowerShell  终端, 即可;

三. Mac Alias

#
# 1. open file: /User/xxx/.bash_profile
# 2. $ source /User/xxx/.bash_profile 
#
# alias list
# git region
alias gitk="sed -i .bak 's/zoomed/normal/g' ~/.config/git/gitk && /usr/local/bin/gitk"
alias local="git config --local --list"
alias global="git config --global --list"
alias gk="gitk --all --date-order&"
alias pull="git pull origin"
alias push="git push origin"
alias prune="git remote prune origin"
alias hf="gitk HEAD..FETCH_HEAD"
alias dhf="gitk HEAD...FETCH_HEAD"
alias tag="git tag --list"
alias gitc="git clone"
#
# mac region
# 
alias hidden="defaults write com.apple.finder AppleShowAllFiles NO"
alias show="defaults write com.apple.finder AppleShowAllFiles YES"
alias csr_off="csrutil disable"
alias csr_on="csrutil enable"
alias du="du -sh * | sort -hr"
#
# python region
#
alias pypath="python -c 'import sys, json;print(json.dumps(sys.path, indent=4))'"
#
# adb region
#
alias ss="~/.tools/screenshot.sh"
alias SS=ss
alias sr="~/.tools/screenrecord.sh"
alias SR=sr
#

3.1 tools

screenshot.sh

#!/bin/bash

dd=`date +%Y%m%d_%H%M%S`
day=`date +%Y%m%d`
media_prefix_directory="/Users/xxx/.tools/Screenshot"
dest_direcotry="${media_prefix_directory}/${day}"
if [ ! -d "${media_prefix_directory}" ]; then
    mkdir $media_prefix_directory
fi
if [ ! -d "${dest_direcotry}" ]; then
    mkdir $dest_direcotry
fi
# adb shell screencap -h
adb shell screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png $dest_direcotry/$dd.png
adb shell rm /sdcard/screenshot.png
echo "the screenshot was saved to "$dest_direcotry/$dd.png
# open $dest_direcotry --reveal
open -a Preview $dest_direcotry/$dd.png

screenrecord.sh

#!/bin/bash

dd=`date +%Y%m%d_%H%M%S`
day=`date +%Y%m%d`
media_prefix_directory="/Users/xxx/.tools/Screenrecord"
dest_direcotry="${media_prefix_directory}/${day}"
if [ ! -d "${media_prefix_directory}" ]; then
    mkdir $media_prefix_directory
fi
if [ ! -d "${dest_direcotry}" ]; then
    mkdir $dest_direcotry
fi
# adb shell screenrecord --help
# adb shell screenrecord --size 1920x1080 --bit-rate 4000000 --verbose /sdcard/screenrecord.mp4
# adb shell screenrecord --time-limit 3 --size 1280x720 --bit-rate 6000000 --verbose /sdcard/screenrecord.mp4

# adb shell screenrecord --time-limit 6 --size 1280x720 --bit-rate 4000000 --verbose /sdcard/screenrecord.mp4
# adb shell screenrecord --time-limit 6 --size 1280x720 --bit-rate 6000000 --verbose /sdcard/screenrecord.mp4
adb shell screenrecord --time-limit 6 --size 1920x1080 --bit-rate 6000000 --verbose /sdcard/screenrecord.mp4

# adb shell screenrecord --time-limit 10 --size 1280x720 --bit-rate 6000000 --verbose /sdcard/screenrecord.mp4
# adb shell screenrecord --time-limit 60 --size 1280x720 --bit-rate 6000000 --verbose /sdcard/screenrecord.mp4
# adb shell screenrecord --time-limit 120 --size 1280x720 --bit-rate 6000000 --verbose /sdcard/screenrecord.mp4
# adb shell screenrecord --time-limit 180 --size 1280x720 --bit-rate 6000000 --verbose /sdcard/screenrecord.mp4
adb pull /sdcard/screenrecord.mp4 $dest_direcotry/$dd.mp4
adb shell rm /sdcard/screenrecord.mp4
echo "the screenrecord was saved to "$dest_direcotry/$dd.mp4
# open $dest_direcotry --reveal
open -a Finder $dest_direcotry/$dd.mp4

执行如下命令, 使得别名设置生效:

# xxx 替换为你的机器上用户名
$ source /User/xxx/.bash_profile 

四. 参考

  1. 如何使用 PowerShell 文档 - PowerShell | Microsoft Docs
  2. Windows PowerShell Language Specification 3.0 - PowerShell | Microsoft Docs
  3. 关于配置文件 - PowerShell | Microsoft Docs

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值