pairedDevices() {
osascript << EOF use framework "IOBluetooth" use scripting additions current application's IOBluetoothDevice's pairedDevices() as listEOF}# 実行すると下記のような出力が得られる# «class ocid» id «data optr0000000070F2E86AB97F0000», «class ocid» id «data optr000000002006E96AB97F0000»
#!/usr/bin/env bashfunctiongetTabs() {
osascript << EOF set _output to "" tell application "Google Chrome" set _window_index to 1 repeat with w in windows set _tab_index to 1 repeat with t in tabs of w set _title to get title of t set _url to get URL of t set _output to (_output & _window_index & "\t" & _tab_index & "\t" & _url & "\t" & _title & "\n") set _tab_index to _tab_index + 1 end repeat set _window_index to _window_index + 1 if _window_index > count windows then exit repeat end repeat end tell return _outputEOF}functionsetActiveTab() {local_window_index=$1local_tab_index=$2
osascript -- - "$_window_index""$_tab_index"<< EOFon run argv set _window_index to item 1 of argv set _tab_index to item 2 of argv tell application "Google Chrome" activate set index of window (_window_index as number) to (_window_index as number) set active tab index of window (_window_index as number) to (_tab_index as number) end tellend runEOF}functionmain() {local selected
IFS=$'\t'read-r-a selected <<(
getTabs |sed'/^$/d'| fzf --delimiter$'\t'--with-nth4--preview'echo {3}'--preview-window down:1 "$@"
)
[${#selected[@]}-lt2]&&return130
setActiveTab ${selected[0]}${selected[1]}}
main "$@"
#!/usr/bin/env bashfunctioncreate_new_tab() {
osascript << EOFtell application "iTerm" tell current window create tab with default profile end tellend tellEOF}functionsend_command() {
osascript -- - "$1"<< EOFon run argvset _command to item 1 of argvtell application "iTerm" tell current window tell current session write text _command end tell end tellend tellend runEOF}functionsplit_vertically() {
osascript << EOFtell application "iTerm" tell current window tell current session select (split vertically with default profile) end tell end tellend tellEOF}functionsplit_horizontally() {
osascript << EOFtell application "iTerm" tell current window tell current session select (split horizontally with default profile) end tell end tellend tellEOF}functionbroadcast_input() {
osascript << EOFtell application "iTerm" activate tell application "System Events" tell application process "iTerm2" tell menu "Shell" of menu bar item "Shell" of menu bar 1 tell menu "Broadcast Input" of menu item "Broadcast Input" click menu item "Broadcast Input to All Panes in Current Tab" end tell end tell end tell end tellend tellEOF}functionselect_session_by_id() {
osascript -- - "$1"<< EOFon run argvset _session_id to item 1 of argvtell application "iTerm" tell session id _session_id of current tab of current window select end tellend tellend runEOF}functionget_current_session_id() {
osascript << EOFtell application "iTerm" tell current session of current tab of current window id end tellend tellEOF}functionget_current_columns() {
osascript << EOFtell application "iTerm" tell current session of current tab of current window columns end tellend tellEOF}functionmulti_ssh_split() {
create_new_tab
localmax_panel_count=3localwidth=$(get_current_columns)localmin_width=$(expr${width} / ${max_panel_count})localtarget_servers=($@)localservers_count=$#localrow=$(expr$servers_count / $max_panel_count)localsession_ids=(`get_current_session_id`)[`expr$servers_count % $max_panel_count`-eq0]&&row=$(expr$row - 1)# split horizontally and store a session idwhile [$row-gt0];do
split_horizontally
row=$(expr$row - 1)session_ids=(${session_ids[@]} `get_current_session_id`)done# select first pane
select_session_by_id ${session_ids[$row]}
send_command "printf '\e]1337;SetBadgeFormat=%s\a' $(/bin/echo -n ${target_servers[0]}| base64)"
send_command "ssh ${target_servers[0]}"[$servers_count-eq1]&&return# -1 is that because ssh first-server via first panelocalvertical_cell_count=$(expr${servers_count} - 1)# split vertically and sshfor i in`seq $vertical_cell_count`;doif [`get_current_columns`-lt$min_width];thenrow=$(expr$row + 1)
select_session_by_id ${session_ids[$row]}else
split_vertically
fi
send_command "printf '\e]1337;SetBadgeFormat=%s\a' $(/bin/echo -n ${target_servers[$i]}| base64)"
send_command "ssh ${target_servers[$i]}"done
broadcast_input
}main() {localtarget_servers=$(cat ~/.ssh/config |grep'Host '|sed's/Host //g'| fzf)[-z"$target_servers"]&&return130
multi_ssh_split ${target_servers[@]}}
main >/dev/null
#!/usr/bin/env bashfunctionget_current_background_color() {
osascript << EOFtell application "iTerm" activate tell current session of current window return background color end tellend tellEOF}functionchange_background_color() {localr=$(echo"scale=2; ($1/255) * 65535"| bc)localg=$(echo"scale=2; ($2/255) * 65535"| bc)localb=$(echo"scale=2; ($3/255) * 65535"| bc)
osascript -- - $r$g$b<< EOFon run argv tell application "iTerm" activate tell current session of current window set red to (item 1 of argv) set green to (item 2 of argv) set blue to (item 3 of argv) set background color to {red, green, blue, 1} end tell end tellend runEOF}# my colorsfunctionprint_colors_rgb() {localcolors=(
# "color_name R G B""Black 0 0 0",
"Red 201 27 0",
"Green 0 194 0",
"Yellow 199 196 0",
"Blue 2 37 199",
"Magenda 201 48 199",
"White 0 197 199",
)
echo${colors[@]}| tr ',''\n'|sed's/^ //g'}functionmain() {local current_color
IFS=','read-a current_color <<(get_current_background_color)localcurrent_color_rgb=(
$(echo"scale=2;(${current_color[0]}/65535)*255"| bc)$(echo"scale=2;(${current_color[1]}/65535)*255"| bc)$(echo"scale=2;(${current_color[2]}/65535)*255"| bc)
)
local color
read-r-a color <<(
print_colors_rgb | fzf --delimiter=""--with-nth1--bind"ctrl-p:execute-silent($0 {2} {3} {4})"
)
if [-z"$color"];then$0${current_color_rgb[@]}else$0${color[@]:1:3}fi}if [$#-eq0];then
main
else
change_background_color $@fi
#!/usr/bin/env bashfunctionchange_transparency() {
osascript -- - $1<< EOFon run argv tell application "iTerm" activate tell current session of current window set transparency to (item 1 of argv as number) end tell end tellend runEOF}functionmain() {localtransparency=$(seq -f "%.1f"0.00.11 \| fzf --header 'transparency' --bind "ctrl-p:execute-silent($0 {})")[-z"$transparency"]&&return
change_transparency $transparency}if [$#-eq0];then
main
else
change_transparency $@fi
#!/usr/bin/env bash## SequelProで指定した接続を開く# 引数にはSequelProの「お気に入り」の行番号を示すインデックスが入る#functionconnect() {
osascript -- - "$@"<< EOFon run argvtell application "Sequel Pro" activate delay 0.5 tell application "System Events" tell process "Sequel Pro" set frontmost to true delay 0.5 repeat with i from 1 to (count argv) keystroke "t" using {command down} tell window "Sequel Pro" delay 0.5 tell outline 1 of scroll area 1 of splitter group 1 of group 2 # because row1 is "QUICK CONNECT" and row2 is "FAVORITES", the top of favorites is row3. set _row_index to (item i of argv as number) + 2 select row _row_index end tell tell scroll area 2 of splitter group 1 of group 2 click button 2 end tell end tell end repeat end tell end tellend tellend runEOF}functionmain() {localfavorites=$(plutil -convert json ~/Library/Application\ Support/Sequel\ Pro/Data/Favorites.plist -o - \| jq -r '."Favorites Root".Children[].name')localtargets=($(echo"${favorites}"| fzf))localrows=()for target in${targets[@]};doecho$targetlocalrow=$(echo"${favorites}"|grep -n ${target}| cut -d ':' -f 1)rows=(${rows[@]}$row)done[${#rows[@]}-eq0]&&return130
connect ${rows[@]}>/dev/null
}
main
#!/usr/bin/env bashfunctionconnect() {localname=$1localhost=$2localusername=$3localpassword=$4localdatabase=$5localport=$6
osascript << EOFtell application "Sequel Pro" activate delay 0.5 tell application "System Events" tell process "Sequel Pro" # 新規タブ作成 set frontmost to true keystroke "t" using {command down} tell window "Sequel Pro" # 「クイック接続」をクリック tell outline 1 of scroll area 1 of splitter group 1 of group 2 select row 1 end tell # DB情報を入力 tell tab group 1 of scroll area 2 of splitter group 1 of group 2 # 名前 set focused of text field 5 to true keystroke "${name}" key code 100 # MySQLホスト delay 0.3 set focused of text field 6 to true keystroke "${host}" key code 100 # ユーザ名 delay 0.3 set focused of text field 4 to true keystroke "${username}" key code 100 # パスワード delay 0.3 set focused of text field 3 to true keystroke "${password}" key code 100 # データベース delay 0.3 set focused of text field 2 to true keystroke "${database}" key code 100 # ポート delay 0.3 set focused of text field 1 to true keystroke "${port}" key code 100 end tell # 接続 tell scroll area 2 of splitter group 1 of group 2 click button 2 end tell end tell end tell end tellend tellEOF}functionmain() {# DB情報はコマンドで取得して渡す想定localname='docker1'localhost='127.0.0.1'localusername='docker'localpassword='docker'localdatabase='testdb'localport='13306'
connect $name$host$username$password$database$port>/dev/null
}
main
set focused of text field 番号 to trueで各テキストフィールドにフォーカスを当てて入力していますが、このテキストフィールドは上から1,2,3...のように連番になっていないので注意です。各テキストフィールドの割当は以下のようになっています。
# 標準タブの場合
text field 1 to true--ポート
text field 2 to true--データベース
text field 3 to true--パスワード
text field 4 to true--ユーザ名
text field 5 to true--名前
text field 6 to true--ホスト# SSHタブの場合
text field 1 to true--名前
text field 2 to true--SSHポート
text field 3 to true--SSHパスワード
text field 4 to true--SSHユーザ
text field 5 to true--SSHホスト
text field 6 to true--ポート
text field 7 to true--データベース
text field 8 to true--パスワード
text field 9 to true--ユーザ名
text field 10 to true--MySQLホスト
# Documentation: https://docs.brew.sh/Formula-Cookbook# https://rubydoc.brew.sh/Formula# PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST!
class Gitblamer < Formula
desc "指定したユーザーの編集したファイルを全て出力するシェルスクリプト。"
homepage ""
url "https://github.com/Rasukarusan/gitblamer/releases/download/0.01/gitblamer"
sha256 "8627dfae4335cbcfc1de18df4e08cc4a571c27d1c9065119b7ffc9139041c536" # depends_on "cmake" => :build
def install
# ENV.deparallelize # if your formula fails when building in parallel # Remove unrecognized options if warned by configure
system "./configure", "--disable-debug",
"--disable-dependency-tracking",
"--disable-silent-rules",
"--prefix=#{prefix}" # system "cmake", ".", *std_cmake_argsendtestdo # `test do` will create, run in and delete a temporary directory. # # This test will fail and we won't accept that! For Homebrew/homebrew-core # this will need to be a test that verifies the functionality of the # software. Run the test with `brew test gitblamer`. Options passed # to `brew install` such as `--HEAD` also need to be provided to `brew test`. # # The installed folder is not in the path, so use the entire path to any # executables being tested: `system "#{bin}/program", "do", "something"`.
system "false"endend
#!/bin/shfunction getTabs() {
osascript << EOF set _output to "" tell application "Google Chrome" set _window_index to 1 repeat with w in windows set _tab_index to 1 repeat with t in tabs of w set _title to get title of t set _url to get URL of t set _output to (_output & _window_index & "\t" & _tab_index & "\t" & _title & "\t" & _url & "\n") set _tab_index to _tab_index + 1 end repeat set _window_index to _window_index + 1 if _window_index > count windows then exit repeat end repeat end tell return _outputEOF
}
function setActiveTab() {
local _window_index=$1local _tab_index=$2
osascript -- -"$_window_index""$_tab_index"<< EOFon run argv set _window_index to item 1 of argv set _tab_index to item 2 of argv tell application "Google Chrome" activate set index of window (_window_index as number) to (_window_index as number) set active tab index of window (_window_index as number) to (_tab_index as number) end tellend runEOF
}
function main() {
local tabs=$(getTabs)local title=$(echo"${tabs}"| awk -F '\t''{print $3}'| fzf)local window_index tab_index
read window_index tab_index <<<"$(echo "${tabs}" | grep -F "${title}" | head -n 1 | awk -F '\t' '{print $1, $2}')"
setActiveTab $window_index$tab_index
}
main