Skip to content

Instantly share code, notes, and snippets.

@halilim
Last active November 12, 2021 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halilim/6f1c30a51577c2b0370415f210093ba1 to your computer and use it in GitHub Desktop.
Save halilim/6f1c30a51577c2b0370415f210093ba1 to your computer and use it in GitHub Desktop.
My Termux customizations. Since I'm not aware of a simpler way of syncing them I just created this. They are mostly subsets of my desktop configs.
#!/bin/bash
# Although this is run by Zsh, Bash shebang is used for shellcheck
alias e='$EDITOR' # Defined in .zshenv
alias ek="echo"
alias le="less"
alias wh="whichh"
alias wb="which_ bat"
alias wl="which_ less"
alias gpl='git pull'
alias vimrc="e ~/.vimrc"
alias zshrc="e ~/.zshrc"
alias zshenv="e ~/.zshenv"
alias psg='ps aux | grep -v " grep " | grep -i'
alias -g 21='2>&1'
alias -g 2D='2>/dev/null'
alias -g G='| grep -in'
alias -g G3='| grep -in -A 1 -B 1'
alias lp='echo $PATH | tr ":" "\n"'
alias lps='echo $PATH | tr ":" "\n" | sort -f'
alias path=lp
alias pg="ping google.com"
alias p1="ping 1.1.1.1"
alias p192="ping 192.168.1.1"
alias tr1="traceroute 1.1.1.1"
alias tr192="traceroute 192.168.1.1"
alias whois_myip='myip_whois'
alias ek="echo"
#!/bin/bash
# Although this is run by Zsh, Bash shebang is used for shellcheck
function my_external_ip() {
# Doesn't recognize proxy (Caches the result?)
# dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"'
curl -fLs ifconfig.me
}
function myip() {
echo '- External:'
my_external_ip
printf '\n- Internal:\n'
local interface
case "$OSTYPE" in
linux-android) interface=wlan0
;;
*) interface=en0
;;
esac
ifconfig $interface | grep 'inet ' | awk "{ print \$2 }"
}
function myip_whois() {
local ip
ip=$(echo_eval my_external_ip)
echo_eval "whois $ip"
}
function which_() {
local name=$1 cmd=$2 file_path
file_path=$(which "$name")
if [[ -f $file_path ]]; then
"$cmd" "$file_path"
else
echo "$file_path"
fi
}
function whichh() {
local input=$1 type_str type_ret
# When it's a variable name
if [[ $input == '$'* ]]; then
printf '%s=' "$input"
eval "echo ""$input"""
return
fi
type_str=$(type "$input")
type_ret=$?
if [[ $type_str == *' function '* ]]; then
whence -v "$input"
printf '\n - Note that the printed function definition may be different from the source - \n\n'
which -x 2 "$input"
elif [[ $type_str == *' alias '* ]]; then
echo "$type_str"
local full_cmd=${type_str#*for } cmd
cmd=${full_cmd%% *}
[[ $cmd == "$input" ]] && return # Prevent infinite loop, e.g. `alias ls=ls -etc`
whichh "$cmd"
elif [[ $type_str == *' is '* ]]; then
local file="${type_str#*is }"
if [[ -L $file ]]; then
ls -l "$file"
else
echo "$type_str"
fi
else
echo "$type_str"
return $type_ret
fi
}

Installation

pkg install git vim
git clone https://gist.github.com/6f1c30a51577c2b0370415f210093ba1.git ~/termux_gist
bash ~/termux_gist/setup.sh

# Then, edit `~/.zshrc`:
ZSH_THEME="sunaku"

Optional: Click and hold > More > Style > install and select color scheme

Updating

cd ~/termux_gist
git pull
#!/usr/bin/env bash
set -euxo pipefail
IFS=$'\n\t'
# https://wiki.termux.com/wiki/ZSH
pkg install zsh
chsh -s zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
ln -s ~/termux_gist/zshenv ~/.zshenv
ln -s ~/termux_gist/vimrc ~/.vimrc
echo "source ~/termux_gist/aliases" >> ~/.zshrc
echo "source ~/termux_gist/functions" >> ~/.zshrc
set nocompatible " We're running Vim, not Vi!
set clipboard=unnamed " Use system clipboard as default clipboard
set cursorline " highlight current line
set number " show line numbers
set showcmd " show command in the last line
set showmatch " highlight matching [{()}]
set splitbelow
set wildmenu " visual autocomplete for command menu
" set textwidth=100
set colorcolumn=100 " See `highlight ColorColumn` below
set hlsearch " highlight matches
set ignorecase " case-insensitive search by default
set smartcase " except when an upper-case letter used in the search
set incsearch " search as characters are entered
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
filetype plugin on " Enable filetype-specific plugins
" Needs to be after filetype plugin - see :h csv-syntax-error
syntax on " Enable syntax highlighting
let mapleader="," " Leader is comma
nnoremap <Leader><space> :nohl<CR>
nnoremap <Leader>b :Buffers<CR>
#!/bin/bash
# Although this is run by Zsh, Bash shebang is used for shellcheck
export EDITOR='vim'
export VISUAL='vim'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment