常用Terminal脚本
使用jq解析sfdx cli output
安装参考:https://command-not-found.com/jq
示例:
#!/bin/bash
# get started -> bash scripts/shell/limits-check.sh
# ref: https://www.baeldung.com/linux/jq-command-json
# ref: https://stedolan.github.io/jq/manual/
# sfdx force:limits:api:display
queryAPILimits() {
echo "start to query the api exeeded the daily limits..."
local result=$(sfdx force:limits:api:display --json | jq -r '.result[] | select(.remaining == 0 and .max != 0) | .name, .max')
echo "API -> Max"
printf "%s -> %d\n" $result
}
# list the api exeeded the daily limits
queryAPILimits
使用history查看历史shell记录
# all shell history
history
# filter git related shell command
history | grep git
# filter gpg related shell command
history | grep gpg
# the same as git log -> count commit times by author
git log | grep yan.xu
效果预览:
创建txt文件
echo "使用苹果自带的录屏软件,快捷键:cmd + shift + 5" > readme.txt
使用cat在terminal中显示文件内容
cat <file_path>
# i.e check readme file
cat README.md
效果预览:
使用pwd查看当前文件路径
pwd
效果预览:
使用treer查看目录结构
# 全局安装
npm install -g treer
# 忽略某些文件或文件夹
treer -i "node_modules"
# 保存目录结构到文件
treer -e "test.txt"
# 示例: 将文件目录结构排除node_modules后,保存到tree.md
treer -e "tree.md" -i "node_modules"
使用Terminal打开VS Code
# to open the entire folder/directory
code .
# to open a specific file
# 语法
code <file_name>
code index.html
# create an empty SFDX project in your local machine
sfdx force:project:create --projectname Hi-CircleCI
# cd into the newly created project folder
cd Hi-CircleCI
# create a folder named “manifest”
mkdir manifest
# type the following command to open the project in VS Code
code .
如果无法使用code .
打开文件夹,参考以下步骤:
复制并移动文件
# 语法
cp <source> <destination>
# 示例
cp server.key ~/Documents/VS\ Code/CircleCI/Hi-CircleCI/buildfiles