2015-02-15 18:50:43 +00:00
|
|
|
Notes for video: https://www.youtube.com/watch?v=Zew0mgJwAh8
|
|
|
|
|
|
|
|
|
|
|
|
## 1. requirements (depends on what u using)
|
|
|
|
* fzf (https://github.com/junegunn/fzf)
|
|
|
|
* bash
|
|
|
|
* zsh
|
|
|
|
* tmux
|
|
|
|
* xclip
|
|
|
|
|
|
|
|
## 2. create folder
|
|
|
|
mkdir ~/.multisnippet
|
|
|
|
|
|
|
|
## 3. alias for zshrc/bashrc
|
2017-04-04 04:04:26 +00:00
|
|
|
# location of snippets, folder created in step 2 or custom location
|
|
|
|
snippets_dir=~/.multisnippet
|
|
|
|
|
2015-02-15 18:50:43 +00:00
|
|
|
# edit single line snippet
|
|
|
|
cfg-snippetrc() { $EDITOR ~/.snippetrc ;}
|
|
|
|
|
|
|
|
# edit multiline snippet
|
2017-04-04 04:04:26 +00:00
|
|
|
cfg-multisnippetrc() { $EDITOR $snippets_dir/"$(ls $snippets_dir | fzf -e -i)" ;}
|
2015-02-15 18:50:43 +00:00
|
|
|
|
|
|
|
#create new multiline snippet
|
2017-04-04 04:04:26 +00:00
|
|
|
multisnippet() { $EDITOR $snippets_dir/"$1" ;}
|
2015-02-15 18:50:43 +00:00
|
|
|
|
|
|
|
fzf-snippet() {
|
|
|
|
selected="$(cat ~/.snippetrc | sed '/^$/d' | sort -n | fzf -e -i )"
|
|
|
|
# remove tags, leading and trailing spaces, also no newline
|
|
|
|
echo "$selected" | sed -e s/\;\;\.\*\$// | sed 's/^[ \t]*//;s/[ \t]*$//' | tr -d '\n' | xclip -selection clipboard
|
|
|
|
}
|
|
|
|
|
|
|
|
fzf-multisnippet() {
|
|
|
|
# merge filename and tags into single line
|
2017-04-04 04:04:26 +00:00
|
|
|
results=$(for FILE in $snippets_dir/*
|
2015-02-15 18:50:43 +00:00
|
|
|
do
|
|
|
|
getname=$(basename $FILE)
|
|
|
|
gettags=$(head -n 1 $FILE)
|
|
|
|
|
|
|
|
echo "$getname \t $gettags"
|
|
|
|
|
|
|
|
done)
|
|
|
|
|
|
|
|
# copy content into clipboard without tags
|
|
|
|
filename=$(echo "$(echo $results | fzf -e -i )" | cut -d' ' -f 1)
|
2017-04-04 04:04:26 +00:00
|
|
|
sed 1d $snippets_dir/$filename | xclip -selection clipboard
|
2015-02-15 18:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
## 4. sample: nano ~/.snippetrc
|
|
|
|
### ( ;; is the delimiter for tags)
|
|
|
|
http://i.imgur.com/CGQJxHi.jpg ;;adblocker thug complains website goes down image meme
|
|
|
|
"Words fall from your mouth as shit from ass!" - Vettius ;;spartacus quote
|
|
|
|
"You counsel to suck the cock that pisses on me!" - Batiatus ;;spartacus quote
|
|
|
|
"What's the point of going out? We're just gonna wind up back here anyway." - Homer Simpson ;;simpsons qoutes cartoon stupid
|
|
|
|
"Operator! Give me the number for 911!" - Homer Simpson ;;simpsons qoutes cartoon stupid
|
|
|
|
|
|
|
|
|
|
|
|
## 5. sample: nano ~/.multisnippet/FILENAME
|
|
|
|
### ( tags are store on the 1st line)
|
|
|
|
|
|
|
|
tags go on this first line
|
|
|
|
# _ _ _ _
|
|
|
|
# __ _ ___ | |_| |__ | | ___| |_ _ _
|
|
|
|
# / _` |/ _ \| __| '_ \| |/ _ \ __| | | |
|
|
|
|
#| (_| | (_) | |_| |_) | | __/ |_| |_| |
|
|
|
|
# \__, |\___/ \__|_.__/|_|\___|\__|\__,_|
|
|
|
|
# |___/
|
|
|
|
# http://www.youtube.com/user/gotbletu
|
|
|
|
# https://twitter.com/gotbletu
|
|
|
|
# https://www.facebook.com/gotbletu
|
|
|
|
# https://plus.google.com/+gotbletu
|
|
|
|
# https://github.com/gotbletu
|
|
|
|
|
2015-02-15 19:07:33 +00:00
|
|
|
## 6. nano ~/.tmux.conf
|
|
|
|
### (optional keybinding for tmux users)
|
|
|
|
#### i use single and double qoute hotkey
|
|
|
|
bind-key "'" new-window -n snippet \; send-keys "fzf-snippet && tmux kill-window\n"
|
|
|
|
bind-key '"' new-window -n multisnippet \; send-keys "fzf-multisnippet && tmux kill-window\n"
|
2015-02-15 18:50:43 +00:00
|
|
|
|
2015-02-15 19:07:33 +00:00
|
|
|
|
|
|
|
## 7. related video
|
2015-02-15 18:50:43 +00:00
|
|
|
* fuzzy finder playlist
|
|
|
|
* https://www.youtube.com/playlist?list=PLqv94xWU9zZ2fMsMMDF4PjtNHCeBFbggD
|
|
|
|
|