Last active
March 1, 2019 20:04
-
-
Save termosa/383f398cbdb848b22aca216dbb65272b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brewup() { | |
brew update | |
brew upgrade | |
brew outdated | |
brew cleanup | |
brew prune | |
} | |
npminit() { | |
let PROJECTNAME | |
if [ $1 ] | |
then | |
PROJECTNAME=$1 | |
else | |
PROJECTNAME=$(basename $(pwd)) | |
fi | |
echo "{\n \"name\": \"$PROJECTNAME\"\n}" > package.json | |
} | |
npmveryclean() { | |
find ~/Source -name "node_modules" -exec trash '{}' + | |
} | |
npm_global_packages=( | |
# NodeJS | |
npm # node package manager | |
ndb # node debugger from Chrome | |
npm-check-updates # check dependency versions | |
# System Tools | |
go # automation tool | |
hotel # web & cli app to start/stop apps | |
alfred-hotel # alfred plugin for hotel | |
livedown # markdown live reolad | |
serve # static web server | |
trash-cli # remove files to system trash | |
) | |
npmconfigure() { | |
npm config set init-version 0.0.0 | |
npm config set init-version 0.0.0 | |
npm config set init-license MIT | |
npm config set ignore-optional true | |
npm config set init-author-email [email protected] | |
npm config set init-author-name "Stanislav Termosa" | |
npm config set init-author-url https://me.st | |
npm config set save-exact false | |
npm config set editor vim | |
npm config set shell zsh | |
} | |
npmup() { | |
npmconfigure | |
npm install -g "${npm_global_packages[@]/#/}" | |
} | |
nvmup() { | |
nvm install node | |
nvm alias default node | |
npmsetup | |
npmup | |
} | |
dash() { | |
"$(open dash://$1)" | |
} | |
mcd() { | |
mkdir -p $1 | |
cd -P $1 | |
} | |
# FZF | |
# fkill - kill process | |
fkill() { | |
pids=$(ps -ef | sed 1d | fzf -m | awk '{print $2}') | |
if [ "x$pids" != "x" ] | |
then | |
echo "$pids" | |
while IFS=$"\n" read -r pid; do kill -${1:-9} $pid; done <<< "$pids" | |
fi | |
} | |
# c - browse chrome history | |
c() { | |
local cols sep | |
cols=$(( COLUMNS / 3 )) | |
sep='{{::}}' | |
# Copy History DB to circumvent the lock | |
# - See http://stackoverflow.com/questions/8936878 for the file path | |
cp -f ~/Library/Application\ Support/Google/Chrome/Default/History /tmp/h | |
sqlite3 -separator $sep /tmp/h \ | |
"select substr(title, 1, $cols), url | |
from urls order by last_visit_time desc" | | |
awk -F $sep '{printf "%-'$cols's \x1b[36m%s\n", $1, $2}' | | |
fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs open | |
} | |
# FZF Finder | |
# pd - look for the project dir | |
pd() { | |
if [ -z "$1" ]; then | |
QUERY=$1 | |
else | |
QUERY="" | |
fi | |
PROJECTNAME="$(ls -d $HOME/Source/*/ | sed 's/.*\/Source\/\(.*\)./\1/' | fzf -1 --query=$1 --preview="tree -L 2 -I 'node_modules|bower_components|test*|spec*|bin|lib' '$HOME/Source/{}' | highlight --syntax=txt -O ansi" --bind=alt-n:preview-down,alt-m:preview-up)" | |
[[ ! -z "$PROJECTNAME" ]] && cd "$HOME/Source/$PROJECTNAME/" | |
} | |
# Modified version where you can press | |
# - ctrl-o to open with `open` command, | |
# - ctrl-e or Enter key to open with the $EDITOR | |
fo() { | |
local out key files | |
out=$(fzf-tmux --query="$1" --multi --select-1 --exit-0 --expect=ctrl-o,ctrl-e) | |
IFS=$'\n' files=($(tail -n +2 <<< $out)) | |
key=$(head -1 <<< "$out") | |
if [ -n "$files" ]; then | |
[ "$key" = ctrl-o ] && open "$files[@]" || ${EDITOR:-vim} -p "$files[@]" | |
fi | |
} | |
# fd - cd to selected directory | |
fd() { | |
local dir | |
dir=$(find ${1:-.} -path '*/\.*' -prune \ | |
-o -type d -print 2> /dev/null | fzf +m) && | |
cd "$dir" | |
} | |
# fda - including hidden directories | |
fda() { | |
local dir | |
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir" | |
} | |
# FZF Git | |
# fcb - checkout git branch | |
fcb() { | |
local branches target | |
branches=$( | |
git branch --all | grep -v HEAD | | |
sort -u | | |
awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}' | |
) || return | |
target=$( | |
echo "$branches" | | |
fzf-tmux -l30 -- --no-hscroll --ansi +m -d "\t" -n 2) || return | |
git checkout $(echo "$target" | awk '{print $2}') | |
} | |
# fct - checkout git tag | |
fct() { | |
local tags target | |
tags=$( | |
git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') || return | |
target=$( | |
echo "$tags" | | |
fzf-tmux -l30 -- --no-hscroll --ansi +m -d "\t" -n 2) || return | |
git checkout $(echo "$target" | awk '{print $2}') | |
} | |
# fcc - checkout git commit | |
fcc() { | |
local commits commit | |
commits=$(git log --pretty=oneline --abbrev-commit --reverse) && | |
commit=$(echo "$commits" | fzf --tac +s +m -e) && | |
git checkout $(echo "$commit" | sed "s/ .*//") | |
} | |
# fco - git commit browser | |
fco() { | |
git log --graph --color=always \ | |
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" | | |
fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \ | |
--bind "ctrl-m:execute: | |
(grep -o '[a-f0-9]\{7\}' | head -1 | | |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF' | |
{} | |
FZF-EOF" | |
} | |
# fsth - easier way to deal with stashes | |
# type fsth to get a list of your stashes | |
# enter shows you the contents of the stash | |
# ctrl-d shows a diff of the stash against your current HEAD | |
# ctrl-b checks the stash out as a branch, for easier merging | |
# ctrl-a apply stash to current HEAD | |
# ctrl-x drop selected stash | |
fsth() { | |
local out q k line sha name | |
while out=$( | |
git stash list --pretty="%C(yellow)%h %gd %>(14)%Cgreen%cr %C(blue)%gs" | | |
fzf --ansi --no-sort --query="$q" --print-query \ | |
--expect=ctrl-d,ctrl-b,ctrl-a,ctrl-x); | |
do | |
IFS=$'\n'; set -f | |
lines=($(<<< "$out")) | |
unset IFS; set +f | |
q="${lines[0]}" | |
k="${lines[1]}" | |
line="${lines[-1]}" | |
sha="${line%% *}" | |
name=$(echo $line | cut -d' ' -f2) | |
[[ -z "$sha" ]] && continue | |
if [[ "$k" == 'ctrl-d' ]]; then | |
git diff $sha | |
elif [[ "$k" == 'ctrl-b' ]]; then | |
git stash branch "stash-$sha" $sha | |
break; | |
elif [[ "$k" == 'ctrl-a' ]]; then | |
git stash apply $name | |
break; | |
elif [[ "$k" == 'ctrl-x' ]]; then | |
git stash drop $name | |
break; | |
else | |
git -c color.ui=always stash show -p $sha | less -+F | |
fi | |
done | |
} | |
# Print all 256 colors to shell | |
function print256() { | |
for i in {0..255} ; do | |
printf "\x1b[48;5;%sm%3d\e[0m " "$i" "$i" | |
if (( i == 15 )) || (( i > 15 )) && (( (i-15) % 6 == 0 )); then | |
printf "\n"; | |
fi | |
done | |
} | |
# | |
# Defines transfer alias and provides easy command line file and folder sharing. | |
# | |
# Authors: | |
# Remco Verhoef <[email protected]> | |
# | |
transfer() { | |
# check arguments | |
if [ $# -eq 0 ]; | |
then | |
echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" | |
return 1 | |
fi | |
# get temporarily filename, output is written to this file show progress can be showed | |
tmpfile=$( mktemp -t transferXXX ) | |
# upload stdin or file | |
file=$1 | |
if tty -s; | |
then | |
basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g') | |
if [ ! -e $file ]; | |
then | |
echo "File $file doesn't exists." | |
return 1 | |
fi | |
if [ -d $file ]; | |
then | |
# zip directory and transfer | |
zipfile=$( mktemp -t transferXXX.zip ) | |
cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile | |
curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile | |
rm -f $zipfile | |
else | |
# transfer file | |
curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile | |
fi | |
else | |
# transfer pipe | |
curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile | |
fi | |
# cat output link | |
cat $tmpfile | |
# cleanup | |
rm -f $tmpfile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment