私はZSHのセットアップを研究してきました。マシン(Mac OS X)をワイプし、XCode(Python)をインストールし、chsh -s zshを実行し、oh-my-zshをインストールしました。
大衆は、スティーブ・ロッシュの「散文」テーマと彼がそれを作る際に書いた彼のチュートリアルについて絶賛しているようです。バッテリー情報を除いて、自分に関連するすべてのものを組み込むことができました。コードは次のとおりです。
batcharge.py
「このスクリプトを自分のディレクトリにある名前のファイルに入れました~/bin/
。もちろん、名前を付けて、好きな場所に配置できます。」
batcharge.py
#!/usr/bin/env python
# coding=UTF-8
import math, subprocess
p = subprocess.Popen(["ioreg", "-rc", "AppleSmartBattery"], stdout=subprocess.PIPE)
output = p.communicate()[0]
o_max = [l for l in output.splitlines() if 'MaxCapacity' in l][0]
o_cur = [l for l in output.splitlines() if 'CurrentCapacity' in l][0]
b_max = float(o_max.rpartition('=')[-1].strip())
b_cur = float(o_cur.rpartition('=')[-1].strip())
charge = b_cur / b_max
charge_threshold = int(math.ceil(10 * charge))
# Output
total_slots, slots = 10, []
filled = int(math.ceil(charge_threshold * (total_slots / 10.0))) * u'▸'
empty = (total_slots - len(filled)) * u'▹'
out = (filled + empty).encode('utf-8')
import sys
color_green = '%{[32m%}'
color_yellow = '%{[1;33m%}'
color_red = '%{[31m%}'
color_reset = '%{[00m%}'
color_out = (
color_green if len(filled) > 6
else color_yellow if len(filled) > 4
else color_red
)
out = color_out + out + color_reset
sys.stdout.write(out)
.zshrc
function battery_charge {
echo `$BAT_CHARGE` 2>/dev/null
}
後で.zshrc
RPROMPT='$(battery_charge)'
私はこれを正確に実行しましたが、バッテリーアイコンがターミナル/iTermに表示されません。私の理解のギャップは、$BAT_CHARGE
電話と~/bin/
配置にあります。スティーブは「もちろん名前を付けて、好きな場所に配置できます...」と指定します。そうであれば、Pythonファイルをランダムな場所に配置した場合、シェルは$BAT_CHARGEに割り当てる値をどのように知るのでしょうか。
アドバイスありがとうございます、
JW