diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 0000000..aa8fd4e --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,49 @@ +FROM alpine:3.12 + +ARG SSH_USER="${SSH_USER:-blink}" +ARG SSH_PASSWORD="${SSH_PASSWORD:-blink}" + +RUN apk --update --no-cache add \ + bash \ + git \ + mosh-server \ + neovim \ + openssh-server \ + tmux \ +&& adduser -D "${SSH_USER}" -s /bin/bash \ +&& echo -e "${SSH_PASSWORD}\n${SSH_PASSWORD}" | passwd "${SSH_USER}" \ +&& ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa \ +&& ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa \ +&& ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa \ +&& ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519 \ +&& chown root:root /etc/ssh \ +&& chmod 0600 /etc/ssh/* \ +&& mkdir -p /root/.ssh \ +&& chmod 0700 /root/.ssh \ +&& rm -rf /var/cache/apk/* \ + /tmp/* \ + /var/tmp/* + +SHELL ["bash", "-c"] + +#COPY ssh_config /etc/ssh/ssh_config +#COPY sshd_config /etc/ssh/sshd_config + +COPY . "/home/${SSH_USER}/.dotfiles"/ +RUN chown -R "${SSH_USER}:${SSH_USER}" "/home/${SSH_USER}" + +USER "${SSH_USER}" +RUN ln -s "/home/${SSH_USER}/.dotfiles/tmux/tmux.conf" "/home/${SSH_USER}/.tmux.conf" \ +&& mkdir -p "/home/${SSH_USER}/.config" \ +&& ln -s "/home/${SSH_USER}/.dotfiles/nvim" "/home/${SSH_USER}/.config/nvim" \ +&& ln -s "/home/${SSH_USER}/.dotfiles/nvim/vimrc" "/home/${SSH_USER}/.vimrc" \ +&& git clone https://github.com/Shougo/dein.vim "/home/${SSH_USER}/.cache/vim/dein/repos/github.com/Shougo/dein.vim" \ +&& nvim -V1 -es -i NONE -N --noplugin -u "/home/${SSH_USER}/.config/nvim/config/vimrc" \ + -c "try | call dein#clear_state() | call dein#update() | finally | messages | qall! | endtry" + +USER root + +EXPOSE 22/tcp +EXPOSE 22022/udp + +CMD ["/usr/sbin/sshd", "-D", "-e", "-f", "/etc/ssh/sshd_config"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc232df --- /dev/null +++ b/README.md @@ -0,0 +1,119 @@ +dotfiles for blink.sh env +========================= + + + +- [Introduction](#introduction) +- [Clipboard](#clipboard) + - [Disclamer](#disclamer) +- [Setup](#setup) +- [Development setup with docker](#development-setup-with-docker) + - [Start and stop service](#start-and-stop-service) + - [Access host from the blink](#access-host-from-the-blink) + + + +# Introduction + +[blink shell](https://blink.sh) is an excellent minimalistic SSH and mosh client +for apple mobile devices. + +For some folks, like me that's a tool #1, I spent most of the time in terminal +(also I work mostly from the iPad pro). + +Here I share blink-related dotfiles and create a development repository. + +Feel free to use, share and of course to contribute! + +# Clipboard + +Paste from iPad to blink works out of the box, but in opposite it depends. If we +copy wrapped lines, usually they breaks. I don't mind apps with menus and +interfaces (i.e. `mc`, `tmux` with window splits, editors, etc.) + +As for now, the perfect solution is to use OSC52 escape codes, these works well +with ssh and recent `mosh`. + +## Disclamer + +In order to get clipboard setup working, we need recent software: tmux 3+, mosh +1.3+, vim 8+ or neovim 4.3+ + +Check your repository first! Usually it means that such apps should be compiled +or installed using [brew](https://brew.sh) (yes, it works with linux too!) + +# Setup + +Clone repository to the .dotfiles folder: + +```shell +git clone http://github.com/andrius/blink-dotfiles ~/.dotfiles +``` + +Tmux setup: + +```shell +ln -s ~/.dotfiles/tmux/tmux.conf ~/.tmux.conf +``` + +VIM or neovim setup: + +```shell +mkdir -p ~/.config +ln -s ~/.dotfiles/nvim ~/.config/nvim +ln -s ~/.dotfiles/nvim/vimrc ~/.vimrc +git clone https://github.com/Shougo/dein.vim ~/.cache/vim/dein/repos/github.com/Shougo/dein.vim +# vim users: replace nvim by vim below +nvim -V1 -es -i NONE -N --noplugin -u "/home/${SSH_USER}/.config/nvim/config/vimrc" \ + -c "try | call dein#clear_state() | call dein#update() | finally | messages | qall! | endtry" +``` + +# Development setup with docker + +It is possible to test stuff with docker. Given dockerfiles just contains `openssh-server` +and `mosh-server`, and minimal setup to get things working. It is possible to +test them directly from the blink shell + +## Start and stop service + +To start: + +```shell +SERVICE=alpine && \ +docker-compose build --force-rm --pull ${SERVICE} && \ +docker-compose up -d ${SERVICE} && \ +docker-compose logs -ft --tail=100 ${SERVICE} +``` + +To stop: + +```shell +docker-compose rm --stop --force +``` + +## Access host from the blink + +Each time when you build new docker image, SSH keys would be updated, so cleanup +known hosts file first: + +``` +rm ~/.ssh/known_hosts +``` + +SSH access: + +```shell +ssh -oPort=22022 blink@host +``` + +mosh access: + +```shell +mosh blink@host -P 22022 -p 22022 +``` + +(if there is issue due to the busy UDP port, you might kill mosh-server first): + +```shell +docker-compose exec alpine killall mosh-server +``` diff --git a/bin/colorband b/bin/colorband new file mode 100755 index 0000000..9315cda --- /dev/null +++ b/bin/colorband @@ -0,0 +1,15 @@ +#!/bin/sh + +awk 'BEGIN{ + s="/\\/\\/\\/\\/\\"; s=s s s s s s s s; + for (colnum = 0; colnum<77; colnum++) { + r = 255-(colnum*255/76); + g = (colnum*510/76); + b = (colnum*255/76); + if (g>255) g = 510-g; + printf "\033[48;2;%d;%d;%dm", r,g,b; + printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b; + printf "%s\033[0m", substr(s,colnum+1,1); + } + printf "\n"; +}' diff --git a/bin/colortest b/bin/colortest new file mode 100755 index 0000000..c12581f --- /dev/null +++ b/bin/colortest @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# +# This file echoes a bunch of color codes to the +# terminal to demonstrate what's available. Each +# line is the color code of one forground color, +# out of 17 (default + 16 escapes), followed by a +# test use of that color on all nine background +# colors (default + 8 escapes). +# + +T='gYw' # The test text + +echo -e "\n 40m 41m 42m 43m\ + 44m 45m 46m 47m"; + +for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ + '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ + ' 36m' '1;36m' ' 37m' '1;37m'; + do FG=${FGs// /} + echo -en " $FGs \033[$FG $T " + for BG in 40m 41m 42m 43m 44m 45m 46m 47m; + do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; + done + echo; +done +echo + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2f9e198 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.9' + +services: + alpine: + build: + context: . + dockerfile: Dockerfile.alpine + image: blink-dotfiles:alpine + environment: + - SSH_USER=blink + - SSH_PASSWORD=blnik + user: ${SSH_USER} + volumes: + - .:/usr/src/blink-dotfiles + ports: + - 0.0.0.0:22022:22/tcp + - 0.0.0.0:22022:22022/udp diff --git a/nvim/Makefile b/nvim/Makefile new file mode 100644 index 0000000..49a18ad --- /dev/null +++ b/nvim/Makefile @@ -0,0 +1,27 @@ +SHELL = /bin/bash +vim := $(if $(shell which nvim),nvim,$(shell which vim)) +vim_version := '${shell $(vim) --version}' +XDG_CACHE_HOME ?= $(HOME)/.cache + +default: install + +install: create-dirs install-dein update-plugins + +update: update-plugins + +upgrade: update + +create-dirs: + @mkdir -vp "$(XDG_CACHE_HOME)/vim/"{backup,session,swap,tags,undo} + +install-dein: + @git clone https://github.com/Shougo/dein.vim ~/.cache/vim/dein/repos/github.com/Shougo/dein.vim + +update-plugins: + $(vim) -V1 -es -i NONE -N --noplugin -u config/vimrc \ + -c "try | call dein#clear_state() | call dein#update() | finally | messages | qall! | endtry" + +uninstall: + rm -rf "$(XDG_CACHE_HOME)/vim" + +.PHONY: install create-dirs update-plugins uninstall diff --git a/nvim/config/vimrc b/nvim/config/vimrc new file mode 100644 index 0000000..8a7a4a0 --- /dev/null +++ b/nvim/config/vimrc @@ -0,0 +1,58 @@ +set nocompatible + +let s:dein_plugin_dir = '~/.cache/vim/dein' +let s:dein_install_dir = s:dein_plugin_dir . '/repos/github.com/Shougo/dein.vim' +execute 'set runtimepath+=' . expand(s:dein_install_dir) + +if has('vim_starting') + if dein#load_state(s:dein_plugin_dir) + let g:dein#auto_recache = 1 + let g:dein#install_max_processes = 12 + call dein#begin(s:dein_plugin_dir) + call dein#add(s:dein_install_dir) + if ! has('nvim') + call dein#add('roxma/nvim-yarp', { 'depends': 'vim-hug-neovim-rpc' }) + call dein#add('roxma/vim-hug-neovim-rpc') + endif + call dein#add('Shougo/deoplete.nvim') + + """ With nvim we should use ojroques's repo, details: https://github.com/fcpg/vim-osc52/issues/6 + call dein#add('ojroques/vim-osc52') + " call dein#add('fcpg/vim-osc52') + + call dein#end() + call dein#save_state() + endif +endif + +filetype plugin indent on +syntax enable + +if ! has('nvim') + set t_Co=256 + " Set Vim-specific sequences for RGB colors + " Fixes 'termguicolors' usage in vim+tmux + " :h xterm-true-color + let &t_8f = "\[38;2;%lu;%lu;%lum" + let &t_8b = "\[48;2;%lu;%lu;%lum" +endif + +" Enables 24-bit RGB color in the terminal +if has('termguicolors') + if empty($COLORTERM) || $COLORTERM =~# 'truecolor\|24bit' + set termguicolors + endif +endif + +" Use system clipboard to get buffers synced between TMUX and VIM +if has('clipboard') && has('vim_starting') + " set clipboard& clipboard+=unnamedplus + set clipboard& clipboard^=unnamed,unnamedplus +endif + +if exists('##TextYankPost') + augroup BlinkClipboardIntegration + autocmd! + autocmd TextYankPost * silent! if v:event.operator ==# 'y' | call SendViaOSC52(join(v:event["regcontents"],"\n")) | endif + augroup END +endif diff --git a/nvim/init.vim b/nvim/init.vim new file mode 100644 index 0000000..7e2286c --- /dev/null +++ b/nvim/init.vim @@ -0,0 +1 @@ +execute 'source' fnamemodify(expand(''), ':h').'/config/vimrc' diff --git a/nvim/vimrc b/nvim/vimrc new file mode 100644 index 0000000..e46d449 --- /dev/null +++ b/nvim/vimrc @@ -0,0 +1,4 @@ +" Note: Skip initialization for vim-tiny or vim-small. +if 1 + execute 'source' fnamemodify(expand(''), ':h').'/config/vimrc' +endif diff --git a/tmux/tmux.conf b/tmux/tmux.conf new file mode 100644 index 0000000..1c7bc67 --- /dev/null +++ b/tmux/tmux.conf @@ -0,0 +1,38 @@ +bind c new-window -c "#{pane_current_path}" + +set -g status-keys vi +setw -g mode-keys vi + +bind | split-window -h -c "#{pane_current_path}" +bind - split-window -v -c "#{pane_current_path}" + +# https://stackoverflow.com/questions/18600188/home-end-keys-do-not-work-in-tmux +bind -n Home if-shell "$is_vim" "send-keys Escape 'OH'" "send-key C-a" +bind -n End if-shell "$is_vim" "send-keys Escape 'OF'" "send-key C-e" + +set -g default-terminal "tmux-256color" +# Update with value from default-terminal +set -ga terminal-overrides ",tmux-256color:Tc" + +# Ms modifies OSC 52 clipboard handling to work with mosh, see +# https://gist.github.com/yudai/95b20e3da66df1b066531997f982b57b +set -ag terminal-overrides "vte*:XT:Ms=\\E]52;c;%p2%s\\7,xterm*:XT:Ms=\\E]52;c;%p2%s\\7" + +# enable OSC 52 clipboard +set -g set-clipboard on + +set -g mouse on + +unbind-key -T copy-mode-vi v +unbind-key -T copy-mode-vi V +unbind-key -T copy-mode-vi y +unbind-key -T copy-mode-vi Enter +unbind-key p +# Begin selection in copy mode. +bind-key -T copy-mode-vi 'v' send -X begin-selection +# Begin rectangle selection in copy mode. +bind-key -T copy-mode-vi 'V' send -X rectangle-toggle +# Yank selection in copy mode. +bind-key -T copy-mode-vi 'y' send -X copy-selection +bind-key -T copy-mode-vi Enter send -X copy-selection +bind p paste-buffer