Upgrade to Pro — share decks privately, control downloads, hide ads and more …

monotips #3 - fzfる

monotips #3 - fzfる

社内LTの資料 monotips #3

Ryotaro Tamura

April 15, 2018
Tweet

More Decks by Ryotaro Tamura

Other Decks in Programming

Transcript

  1. લఏ ‣ NBD04ͷ৔߹ʹඞཁͳ΋ͷ ‣ CBTIY ‣ 3&"%-*/&@-*/& 3&"%-*/&@10*/5͕Yͩͱ࢖͑ͳ͍ ‣ CSFXͳͲͰΠϯετʔϧ

    ‣ [TIͱ͔Ͱ΋0, ଟ෼#6''&3 $63403  ‣ G[Gͷجຊઃఆ ‣ IFJHIUG[Gͷը໘αΠζΛมߋ σϑΥϧτ͸શը໘  ‣ SFWFSTFΫΤϦͷೖྗཝΛը໘্෦ʹมߋ ‣ CPSEFSG[Gͷը໘ͱλʔϛφϧͷڥքʹϘʔμʔදࣔ brew install bash echo '/usr/local/bin/bash' | sudo tee -a /etc/shells chsh -s /usr/local/bin/bash export FZF_DEFAULT_OPTS='--height 40% --reverse --border'
  2. G[GͰ֊૚Λඈ͹ͯ͠DE function fd() { local dir=$(find ${1:-.} -maxdepth ${2:-10} -type

    d | sed 's/^\.\///' | # 相対パスの "./" を除去 grep -v "\/\." | # 隠しディレクトリ除外 grep -v "^\." | # 隠しディレクトリ除外 fzf —no-multi) cd "$dir" }
  3. HJUͷϒϥϯν੾Γସ͑ function fbr() { local branches branch branches=$(git branch -vv)

    && branch=$(echo "$branches" | fzf --no-multi) && git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //") }
  4. IJTUPSZΛG[GͰݕࡧ function fzf-select-history() { READLINE_LINE=$(HISTTIMEFORMAT= history | tac | gsed

    -e 's/^\s*[0-9]\+\s\+//' | # 履歴番号を除去 awk '!a[$0]++' | # 重複を除外 fzf --no-sort) READLINE_POINT=${#READLINE_LINE} } bind -x '"\C-r": fzf-select-history’ # Ctrl+rでfunctionを呼び出し ‣ 3&"%-*/&@-*/& ‣ CBTIͷSFBEMJOFͷόοϑΝʹࢦఆจࣈΛೖྗ͢Δ ‣ ࣍ͷೖྗ଴ड͕࢝·ͬͨ࣌ʹطʹೖྗ͞Εͨঢ়ଶʹͳΔ ‣ 3&"%-*/&@10*/5 ‣ ΧʔιϧͷҐஔΛࢦఆ ‣ 3&"%-*/&@-*/&ͷจࣈ਺Λࢦఆͯ͠ɺΧʔιϧΛ຤ඌʹҠಈ
  5. BDLͱG[GͰίʔυݕࡧ function fck() { local out query file line while

    out=$(ack "$@" . | fzf --no-height -e --no-sort \ --query=“$query” —print-query); do query=$(head -1 <<< "$out") file=$(sed '1d' <<< "$out" | awk -F : '{print $1}') line=$(sed '1d' <<< "$out" | awk -F : '{print $2}') [ -z "$file" ] && continue less -N -R +$line $file done } ‣ Ҿ਺ͳ͠ͰΧϨϯτσΟϨΫτϦҎԼͷશιʔείʔυΛදࣔ ‣ FOUFSΛԡ͢ͱߦҐஔΛࢦఆͯ͠MFTTͰ։͘ ‣ MFTTΛൈ͚Δͱ࠶ͼG[Gͷը໘ʹ໭Δ ΫΤϦจࣈ͸Ҿ͖ܧ͙  ‣ ةݥͳ߳Γ͕͢Δؔ਺໊͚ͩͲؾʹ͠ͳ͍ͰͶ
  6. GDLิ଍ ‣ XIJMFPVU DPNNBOE EPdEPOF ‣ DPNNBOEͷFYJUDPEF͕ͳΒɺEPdEPOF಺ͷॲཧΛ࣮ߦ͠ɺ FYJUDPEF͕Ҏ֎ʹͳΔ·Ͱϧʔϓɻ ‣ G[Gͷฦ͢FYJUDPEF

    ‣ /PSNBMFYJU FOUFS΍FYQFDUͰࢦఆͨ͠Ωʔ  ‣ /PNBUDI ‣ &SSPS ‣ $53-$PS&4$ ‣ G[Gͷग़ྗ͸PVUʹೖ͍ͬͯΔͷͰɺՃ޻ͯ͠MFTT΁౉͢ ‣ G[GQSJOURVFSZ ‣ ग़ྗ͕ҎԼͷ௨ΓʹͳΔ ‣ ߦ໨G[G಺Ͱೖྗ͍ͯͨ͠ΫΤϦ ‣ ߦ໨બ୒ͨ͠ߦ σϑΥϧτ͸͜Ε͚ͩ  ‣ MFTTΛൈ͚Δͱɺ࠶౓XIJMFͷDPNNBOE G[G ͕࣮ߦ͞ΕΔ ‣ RVFSZΦϓγϣϯʹग़ྗͷߦ໨Λ౉ͯ͠ΫΤϦҾ͖ܧ͗