取り敢えず「書き出し」とか「算数」なら対応しそうだ。言うならば、小学生低学年のレベルだな。今後の発展が期待できる。むしろ「Playgrond」を飛び出して、「Swift as a shell script on Terminal」なんて運用ができるといいのだが。
追伸:
「Xcode -> terminal」と来ると、エディターの色も黒色系にしたくなってきた。
____
この記事の履歴
- 開始 2015-04-27(月) 08:30:06
#!/bin/zsh簡単な処理なら、「grep」「sed」「awk」の様な難しい文法を利用しないでも、何とかなりそうだ。
# d0l: Delete blank(0) Line from file.
#
# References:
# 1) "From Bash to Z Shell", Oliver Kiddle et.al., Chapter 13, p331-2.
# 2) "試験運用中なLinux備忘録: ファイルの内容を1行ずつ処理"
# http://d.hatena.ne.jp/kakurasan/20100112/p1
#
# Usage: d0l «file name»
#
# 2015-04-18(土) 14:21:07 by mNeji
#
file="$1"
cat "$file" | \
while read line; do
[[ "$line" =~ '^$' ]] && : || echo "$line"
done
#!/bin/zsh # we: "Wifi state Exchanger" script for Yosemite # Usage: # • we⏎ : normal opration: exchange state(on/off) of Wi-Fi. # • we n⏎: normal operation with no output. # • we i⏎: airport -I # • we s⏎: airport -s # 2015-04-15 11:12:27 from won/wof, by mNeji. # variables local Pctrol a api apa inp etp local pre_status chg_status local my_initial my_now nsec cen1 # input parameter Pctrol="$1" # direct definition to the command 'airport' for general purose a="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/" a=${a}Current/Resources/airport # airport call & finish if [[ "$Pctrol" = "i" ]]; then $a -I; return elif [[ "$Pctrol" = "s" ]]; then $a -s; return fi # set status for previous and changed pre_status=$([[ "$(ipconfig getifaddr en1 )" = "" ]] && echo "off" || echo "on") #echo $pre_status [[ "$pre_status" = "off" ]] && chg_status="on" || chg_status="off" #echo $pre_status #echo $chg_status # Change Airport status networksetup -setairportpower en1 $chg_status # set initial date in unit of 'sec' my_initial=$(date +%s) # main waiting loop until 'netstat' contain en1 conpornents. while : ; do my_now=$(date +%s) nsec=$(($my_now-$my_initial)) if [[ "$Pctrol" = "" ]]; then printf "\rWi-Fi:$pre_status → passed(sec): %d" $nsec fi cen1=$(netstat -r -f inet | grep en1) # s=$(ipconfig getifaddr en1) # it was worked at Mavericks. [[ "$cen1" = "" ]] && continue || break done if [[ "$Pctrol" = "" ]]; then echo -n "\rWi-Fi[$pre_status→(${nsec}sec)→$chg_status] " fi # list up status for wifi api=$($a -I |grep "^ *SSID: " |sed 's/^ *//g' |cut -d' ' -f2) apa=$($a -I |grep "^ *BSSID: " |sed 's/^ *//g' |cut -d' ' -f2) inp=$(ifconfig en1 | grep 'inet ' | cut -d' ' -f2) etp=$(ifconfig en1 | grep ether | cut -d' ' -f2) if [[ "$Pctrol" = "" ]]; then if [[ "$chg_status" = "on" ]]; then echo "$api($apa)⥢⥤ $inp($etp)" else echo "AccessPoint is idle." fi fi____
#!/bin/zsh # # myHost: # # Usage & outputs: # % myHost⏎ # •System Version: Mac OS X: 10.10.2(14C1514) # •Host Name: MmM11.local # •Boot Volume: sh3X10.2 # •LAN Ports: (1) Ether:"*" 10.9.8.100 # (2) Wi-Fi:"*" 10.9.8.101 getHostInfo() { sysName=$(sw_vers -productName) sysVersion=$(sw_vers -productVersion) sysBuild=$(sw_vers -buildVersion) hostName=$(hostname) etherIP=$(ipconfig getifaddr en0) wifiIP=$(ipconfig getifaddr en1) myd=$( ls -l /Volumes/ | grep " -> " |\ sed -e "s%.* \([a-zA-Z0-9._-]*\) -> /$%\1%") echo " •System Version: $sysName $sysVersion($sysBuild)" echo " •Host Name: $hostName" echo " •Boot Volume: $myd" echo " •LAN Ports: (1) $LAN_Name[1]:\"$LAN_State[1]\" $LAN_IP[1]" echo " (2) $LAN_Name[2]:\"$LAN_State[2]\" $LAN_IP[2]" return } getLANportsOrder(){ set -a LAN_Name=() set -a LAN_IP=() set -a LAN_State=() local portOrder, wifiIP, wifiState, etherIP, etherState # 「(数字 )の行を切り出す。 portOrder=$(networksetup -listnetworkserviceorder | grep "(\d) ") #echo "$portOrder" # Wi-Fi setting Nwifi=$(( $(echo $portOrder | grep "Wi-Fi$" | cut -c2) )) LAN_Name=( Wi-Fi ) wifiIP=$(ipconfig getifaddr en1) if [[ $wifiIP = "" ]]; then wifiIP="not active: turned off" wifiState="_" else wifiState="*" fi LAN_IP=( $wifiIP ) LAN_State=( $wifiState ) #echo "Nwifi=$Nwifi" # Ethernet setting Nether=$(( $(echo $portOrder | grep "Ethernet$" | cut -c2) )) etherIP=$(ipconfig getifaddr en0) if [[ $etherIP = "" ]]; then etherIP="not active: turned off" etherState="_" else etherState="*" fi if [[ $Nwifi -gt $Nether ]] ; then LAN_Name=( Ether $LAN_Name ) LAN_IP=( $etherIP $LAN_IP ) LAN_State=( $etherState $LAN_State ) else LAN_Name=( $LAN_Name Ether ) LAN_IP=( $LAN_IP $etherIP ) LAN_State=( $LAN_State $etherState ) fi #echo $LAN_Name #echo $LAN_IP #echo $LAN_State # #echo " (1) $LAN_Name[1]:\"$LAN_State[1]\" $LAN_IP[1] " #echo " (2) $LAN_Name[2]:\"$LAN_State[2]\" $LAN_IP[2] " } # 実行 getLANportsOrder getHostInfo
近頃、ようやくKarabiner-Elementsに慣れてきたので、 Terminalで動作する「擬似Vi-Mode」を作って見たので、ご紹介します。 『概要』 「擬似Vi-Mode」の所以は、方向キー「←↓↑→」を通常の「hjkl」ではなくて「jkil」としました。これ...