summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2022-04-06 12:17:27 +0000
committerbrian m. carlson <sandals@crustytoothpaste.net>2022-04-06 12:17:27 +0000
commit0ac2f735793d4af1da48a719b3039006522c12b5 (patch)
tree5bf25300cca00ae98b5cd3d3154deaf6a1e56f6f
parent8a8a9b36d1c8c00a552097a4ad918029c90caf4c (diff)
WIPlawn
-rwxr-xr-xbin/dct-clip25
-rw-r--r--spec/zsh_spec.rb30
-rw-r--r--zsh/zshenv46
3 files changed, 75 insertions, 26 deletions
diff --git a/bin/dct-clip b/bin/dct-clip
index f6d95cd..06d9e09 100755
--- a/bin/dct-clip
+++ b/bin/dct-clip
@@ -5,14 +5,22 @@ require 'shellwords'
COMMANDS = {
copy: [
- ->(options) { ["pbcopy"] },
- ->(options) { ["xclip","-i", "-selection", options[:location].to_s] },
- ->(options) { ["xsel", "-i", options[:location] == :clipboard ? "-b" : "-p"] },
+ {
+ func: ->(options) { ["lawn", "run", "--", "clip", "-i", options[:location] == :clipboard ? "-b" : "-p"] },
+ if: ->() { ENV["REMOTE_ENV"] }
+ },
+ {func: ->(options) { ["pbcopy"] }},
+ {func: ->(options) { ["xclip","-i", "-selection", options[:location].to_s] }},
+ {func: ->(options) { ["xsel", "-i", options[:location] == :clipboard ? "-b" : "-p"] }},
],
paste: [
- ->(options) { ["pbpaste"] },
- ->(options) { ["xclip", "-o", "-selection", options[:location].to_s] },
- ->(options) { ["xsel", "-o", options[:location] == :clipboard ? "-b" : "-p"] },
+ {
+ func: ->(options) { ["lawn", "run", "--", "clip", "-o", options[:location] == :clipboard ? "-b" : "-p"] },
+ if: ->() { ENV["REMOTE_ENV"] }
+ },
+ {func: ->(options) { ["pbpaste"] }},
+ {func: ->(options) { ["xclip", "-o", "-selection", options[:location].to_s] }},
+ {func: ->(options) { ["xsel", "-o", options[:location] == :clipboard ? "-b" : "-p"] }},
]
}
@@ -62,7 +70,10 @@ end
def find_command(commands, options)
commands.each do |cmd|
- cmd = cmd.call(options)
+ if cmd[:if] && !cmd[:if].call
+ next
+ end
+ cmd = cmd[:func].call(options)
return cmd if which(cmd[0])
end
nil
diff --git a/spec/zsh_spec.rb b/spec/zsh_spec.rb
index f9e5e7f..b365c7b 100644
--- a/spec/zsh_spec.rb
+++ b/spec/zsh_spec.rb
@@ -8,22 +8,46 @@ describe :zsh do
context 'editor' do
it 'should set EDITOR to nvim-gtk with DISPLAY' do
@dir = TestDir.new
- exes = %w[nvim-gtk gvim mvim ex nvim vimx vim vi]
+ exes = %w[lawn nvim-gtk gvim mvim ex nvim vimx vim vi]
expect(@dir.cmd_with_exes(exes, ['zsh', '-c', 'echo $EDITOR'], 'DISPLAY' => 'something')).to eq "nvim-gtk --no-fork\n"
end
it 'should set VISUAL to nvim-gtk with DISPLAY' do
@dir = TestDir.new
- exes = %w[nvim-gtk gvim mvim ex nvim vimx vim vi]
+ exes = %w[lawn nvim-gtk gvim mvim ex nvim vimx vim vi]
expect(@dir.cmd_with_exes(exes, ['zsh', '-c', 'echo $VISUAL'], 'DISPLAY' => 'something')).to eq "nvim-gtk --no-fork\n"
end
it 'should set set detachable editor to nvim-gtk with DISPLAY' do
@dir = TestDir.new
- exes = %w[nvim-gtk gvim mvim ex nvim vimx vim vi]
+ exes = %w[lawn nvim-gtk gvim mvim ex nvim vimx vim vi]
expect(@dir.cmd_with_exes(exes, ['zsh', '-c', 'bmc_editor --detach --no-fallback'], 'DISPLAY' => 'something')).to eq "nvim-gtk"
end
+ it 'should set EDITOR to lawn with REMOTE_ENV' do
+ @dir = TestDir.new
+ exes = %w[lawn nvim-gtk gvim mvim ex nvim vimx vim vi]
+ expect(@dir.cmd_with_exes(exes, ['zsh', '-c', 'echo $EDITOR'], 'REMOTE_ENV' => 'something')).to eq "lawn run -- gvi --no-fork\n"
+ end
+
+ it 'should set VISUAL to lawn with REMOTE_ENV' do
+ @dir = TestDir.new
+ exes = %w[lawn nvim-gtk gvim mvim ex nvim vimx vim vi]
+ expect(@dir.cmd_with_exes(exes, ['zsh', '-c', 'echo $VISUAL'], 'REMOTE_ENV' => 'something')).to eq "lawn run -- gvi --no-fork\n"
+ end
+
+ it 'should set set detachable editor to lawn with REMOTE_ENV' do
+ @dir = TestDir.new
+ exes = %w[lawn nvim-gtk gvim mvim ex nvim vimx vim vi]
+ expect(@dir.cmd_with_exes(exes, ['zsh', '-c', 'bmc_editor --detach --no-fallback'], 'REMOTE_ENV' => 'something')).to eq "lawn run -- gvi"
+ end
+
+ it 'should set BROWSER to lawn with REMOTE_ENV' do
+ @dir = TestDir.new
+ exes = %w[lawn nvim-gtk gvim mvim ex nvim vimx vim vi]
+ expect(@dir.cmd_with_exes(exes, ['zsh', '-c', 'echo $BROWSER'], 'REMOTE_ENV' => 'something')).to eq "lawn run -- browser\n"
+ end
+
it 'should prefer gvim with DISPLAY and no nvim-gtk' do
@dir = TestDir.new
exes = %w[gvim mvim ex nvim vimx vim vi]
diff --git a/zsh/zshenv b/zsh/zshenv
index d0300f1..63eec17 100644
--- a/zsh/zshenv
+++ b/zsh/zshenv
@@ -28,6 +28,13 @@ setup_browser () {
local i=""
local chrome="google-chrome-beta chromium-browser chromium google-chrome"
local firefox="firefox iceweasel"
+
+ if [[ -n "$REMOTE_ENV" ]] && command -v lawn >/dev/null 2>&1
+ then
+ export BROWSER="lawn run -- browser"
+ return
+ fi
+
for i in $firefox $chrome
do
if command -v "$i" >/dev/null 2>&1
@@ -88,7 +95,7 @@ setup_temp () {
}
bmc_editor () {
- local console="" dumb="" display="" detach="" fallback=t
+ local console="" dumb="" display="" detach="" fallback=t remote=""
while [[ -n $1 ]]
do
@@ -109,26 +116,29 @@ bmc_editor () {
[[ -n $DISPLAY ]] && display=t
[[ $TERM = dumb ]] && dumb=t
+ [[ -n $REMOTE_ENV ]] && remote=t
local i
- for i in 'nvim-gtk --no-fork' 'gvim -f' 'mvim -f' nvim-gtk gvim mvim nvim vimx vim vi ex
+ for i in 'lawn run -- gvi --no-fork' 'lawn run -- gvi' 'nvim-gtk --no-fork' 'gvim -f' 'mvim -f' nvim-gtk gvim mvim nvim vimx vim vi ex
do
local root="${i%% *}"
local ok=""
- # True if there are no arguments to the command.
- local root_only="$([ "$i" = "$root" ] && echo t)"
- case "$root:$root_only:$detach:$console:$dumb:$display:$OSTYPE" in
- nvim-gtk::::*:t:*) ok=t;;
- nvim-gtk:t:t::*:t:*) ok=t;;
- gvim::::*:t:*) ok=t;;
- gvim:t:t::*:t:*) ok=t;;
- mvim::::*:*:darwin) ok=t;;
- mvim:t:t::*:*:darwin) ok=t;;
- ex:*::*:t:*:*) ok=t;;
- nvim:*::*::*:*) ok=t;;
- vimx:*::*::*:*) ok=t;;
- vim:*::*::*:*) ok=t;;
- vi:*::*::*:*) ok=t;;
+ # True if the command doesn't contain an argument to detach from the terminal.
+ local simple="$([ -n "${i##*--no-fork}" -a -n "${i##*-f}" ] && echo t)"
+ case "$root:$simple:$detach:$console:$dumb:$display:$remote:$OSTYPE" in
+ lawn::::*::t*) ok=t;;
+ lawn:t:t::*::t:*) ok=t;;
+ nvim-gtk::::*:t:*:*) ok=t;;
+ nvim-gtk:t:t::*:t:*:*) ok=t;;
+ gvim::::*:t:*:*) ok=t;;
+ gvim:t:t::*:t:*:*) ok=t;;
+ mvim::::*:*:*:darwin) ok=t;;
+ mvim:t:t::*:*:*:darwin) ok=t;;
+ ex:*::*:t:*:*:*) ok=t;;
+ nvim:*::*::*:*:*) ok=t;;
+ vimx:*::*::*:*:*) ok=t;;
+ vim:*::*::*:*:*) ok=t;;
+ vi:*::*::*:*:*) ok=t;;
esac
if [[ -n "$ok" ]] && command -v "$root" >/dev/null 2>&1
@@ -227,6 +237,10 @@ then
unset ver
fi
+if [[ -n "$CODESPACES" ]]; then
+ REMOTE_ENV=codespaces
+fi
+
LANG=$(preferred_locale)
LC_ADDRESS=en_CA.UTF-8
LC_COLLATE=$(preferred_locale)