分享:Charles 的指令碼工具盒

Charles發表於2022-11-27

昨天釋出了《30 個方便的 Bash shell 別名》之後,一位讀者也向我們分享了他的工具盒,特此向大家推薦:Charles 的指令碼。這個工具盒可以配合作者的部落格:《Ubuntu Gnome 酷炫完整指南系列》使用。

他的指令碼或許寫得不夠精妙,也許會存在一些 bug,但是正是這種對工作、生活中的積累進行整理,才是 Linux 生活的樂趣和進取之道。大家喜歡的話,也可以貢獻自己的程式碼和貢獻,使之更加完善。

以下內容引自他的專案說明

分享:Charles 的指令碼工具盒

你為什麼要安裝本專案?

凡是喜歡折騰的朋友肯定經常會遇到下面幾個困擾:

  1. 作業系統被自己搞爛,需要重灌,難受!
  2. 換了新電腦 / 工作環境,一切常用工具又需要重新部署,麻煩!
  3. 許多外掛配置起來太複雜了,缺少自動或版自動化的工具
  4. 常用的命令就那麼幾個,還又長又複雜(說的就是你!aptgit

內容介紹

最初因為我經常會因為愚蠢的操作把作業系統搞得崩潰,寫下了本專案以便減輕重灌系統之痛。後來我寫了許多方便的小工具和指令碼,把它們整合起來就變成了本專案:

1. 備份/恢復

本專案會將所有資料備份到 $CHARLES_BACKUP 即 ~/.config/CharlesBackup,可以使用網盤或 git 自動上傳備份(git備份已經整合在charles-update命令中)

下面是是相關命令介紹:

  • add-ppa: 新增 ppa 的時候同時備份 ppa 列表,在fish-shell中執行 add-ppa (add-ppa) 可以自動新增列表中全部 ppa
  • inst: 使用 apt 安裝軟體的時候同時備份軟體名,在fish-shell中執行 inst (inst) 可以自動安裝列表中全部軟體
  • gnome-shell-extensions-backup 和 gnome-shell-extensions-restore: 備份和恢復 Gnome 桌面的外掛
  • omf-backup 和 omf-restore: 備份和恢復 oh-my-fish(fish-shell 的包管理器)的外掛列表
  • charles-backup: 呼叫上述部分命令備份各種外掛(可以放到 cronjob 裡面實現自動備份)
  • charles-update: 更新本專案及相關依賴;自動使用git上傳備份

2. 小工具

通知類:

  • ef、 fifo: ef 相當於一個短時備忘錄,可以用來記錄筆記,相當於編輯 fifo 命令;輸入fifo即可執行之前寫入的內容。
  • notify: 提醒你一定時間之後做某事
  • tomato: 簡單的蕃茄鍾,定時執行 fifo 命令

系統操作:

  • update: 相當於 pacman -Syyu,更新所有軟體
  • apt-unlock: 刪除 apt 因為異常退出而沒有刪掉的檔案鎖
  • get-path: 獲得選定的檔案絕對路徑,並放到剪貼簿內
  • mac-addr-flush: 重置 MAC 地址(重啟失效)
  • wallpaper-earthview: 更新桌面桌布(需要先設定好桌面桌布位置為 ~/.cache/wallpaper/background-image.jpg

其他:

  • ssr: ShadowSocksR 的一鍵安裝、配置、使用客戶端
  • aria2c-daemon-start: 啟動 aria2 的下載服務
  • gh-md-toc: Forked 自 gh-md-toc, 為 GitHub 的 Markdown 檔案加入目錄
  • gojuon: 日語五十音學習小工具
  • ipgw ipgw_py: 命令列版的東北大學校園網登入器

網頁相關:

  • wechat: 開啟微信
  • pocket: 開啟 Pocket
  • shanbay: 開啟扇貝單詞

包含在 .bashrc 或 fish-shell config.fish 中的簡便操作:

寫在CharlesScripts/charles/shell.rc.d中的指令碼函式:

  • backup: 將檔案備份(複製一份並新增.bak字尾)
  • clscd 到指定資料夾然後ls
  • dict: 將 dict 查到的單詞輸出到less內,以免單詞解釋過長顯示不完還要再翻回去看
  • g: 使用git一條龍地執行 git add -Agit diff --cachedgit statusgit commit -m <commit message>git push,並檢查 push 是否成功,若失敗則提醒你檢查一下
  • mcd: 先mkdircd到剛剛建立的資料夾內
  • md5checkmd5check <file> <md5>,用grep檢查md5是否一樣
  • viz: 使用graphviz編譯為指定格式的圖片,用法為viz source.dot png

CharlesScripts/charles/installation.d/conf.d/config-fish配置好的命令縮寫

  • ... -> cd ...
  • c -> clear; cd
  • cl -> cd ..;ls
  • eg -> grep -E
  • ftps -> python3 -m http.server 8080: 快速開啟一個簡易 ftp 伺服器
  • gaa -> git add -A
  • gb -> git branch -c
  • gck -> git checkout
  • gcm -> git commit -m
  • gl -> git l: 顯示結構化的 git 日誌
  • gm -> git merge --no-ff
  • gp -> git push
  • gpl -> git pull
  • gst -> git status
  • histg -> history | grep
  • i -> ipython --no-confirm-exit --no-banner --pprint -i --pylab=auto
  • l -> ls --color=auto
  • la -> ls --almost-all --color=auto
  • le -> ls --almost-all --color=auto|egrep
  • lg -> ls --almost-all --color=auto|grep
  • ll -> ls --almost-all -lh --color=auto
  • n -> xdg-open .
  • o -> xdg-open
  • p -> python
  • pdb -> python -mpowerline.bindings.pdb
  • su -> sudo su
  • u -> update

3. 安裝軟體

指令碼在 CharlesScripts/charles/installation.d/get.d

標 * 的是推薦安裝的

get.d/
├── get-calibre
├── get-docker
├──*get-fasd
├──*get-oh-my-fish
├──*get-powerline
├── get-spacemacs
├── get-spacevim
├── get-sublime-text-3
├──*get-thefuck
└── get-xsh

4. 配置軟體

指令碼在 CharlesScripts/charles/installation.d/conf.d

標 * 的是推薦安裝的

conf.d/
├──*config-bash
├──*config-fish
├──*config-git
├──*config-gnome
├──*config-powerline-bash
├── config-powerline-ipython
└──*config-tmux

安裝指南

裝前必讀:

  • 本專案並未經過大量測試,需要讀者有基本的 Linux 問題處理能力
  • 支援的作業系統:Arch Linux 或 Ubuntu Gnome 最新LTS版
  • 依賴項(需要使用者自行安裝): Nerd Fonts, Google Chrome, curl
  • 可選項:Anaconda, ipython (>=5.0), fortune-zh

逐步安裝:

  1. 安裝依賴
  2. 下載本專案:git clone https://github.com/the0demiurge/CharlesScripts.git ~/.local/share/CharlesScripts
  3. cd ~/.local/share/CharlesScripts/charles/installation.d
  4. 閱讀並執行相關軟體安裝指令碼和配置指令碼。

安裝指令碼(測試中):

bash <(curl -L https://git.io/get-charles)

效果圖

按照《Ubuntu Gnome 酷炫完整指南系列》介紹的內容配置後如下圖所示。

分享:Charles 的指令碼工具盒

分享:Charles 的指令碼工具盒

相關文章