diff --git a/etc/lf.fish b/etc/lf.fish deleted file mode 100644 index acc9fd52..00000000 --- a/etc/lf.fish +++ /dev/null @@ -1,22 +0,0 @@ -# Change working dir in fish to last dir in lf on exit (adapted from ranger). -# -# You need to either copy the content of this file to ~/.config/fish/config.fish -# or put the file to ~/.config/fish/functions using something like: -# -# mkdir -p ~/.config/fish/functions -# ln -s "$GOPATH/src/github.com/gokcehan/lf/etc/lf.fish" ~/.config/fish/functions -# - -function lf - set tmp (mktemp) - command lf -last-dir-path=$tmp $argv - if test -f "$tmp" - set dir (cat $tmp) - if test -n "$dir" - if test "$dir" != (pwd) - cd $dir - end - end - end - rm -f $tmp -end diff --git a/etc/lf.sh b/etc/lf.sh deleted file mode 100644 index 29b7a42d..00000000 --- a/etc/lf.sh +++ /dev/null @@ -1,24 +0,0 @@ -# Change working dir in shell to last dir in lf on exit (adapted from ranger). -# -# You need to either copy the content of this file to your shell rc file -# (e.g. ~/.bashrc) or source this file directly using something like: -# -# LFSH="$GOPATH/src/github.com/gokcehan/lf/etc/lf.sh" -# if [ -f "$LFSH" ]; then -# source "$LFSH" -# fi -# -# You may also like to assign a key to this command: -# -# bind '"\C-o":"\C-ulf\C-m"' -# - -lf () { - tmp="$(mktemp)" - command lf -last-dir-path="$tmp" "$@" - if [ -f "$tmp" ]; then - dir="$(cat "$tmp")" - [ "$dir" != "$(pwd)" ] && cd "$dir" - fi - rm -f "$tmp" -} diff --git a/etc/lf.vim b/etc/lf.vim index 9efe59ea..6102f1fb 100644 --- a/etc/lf.vim +++ b/etc/lf.vim @@ -1,16 +1,16 @@ -" Use lf to select and open a file in vim (adapted from ranger). +" Use lf to select and open file(s) in vim (adapted from ranger). " " You need to either copy the content of this file to your ~/.vimrc or source -" this file directly using something like: +" this file directly: " -" let lfvim = $GOPATH . "/src/github.com/gokcehan/lf/etc/lf.vim" +" let lfvim = "/path/to/lf.vim" " if filereadable(lfvim) " exec "source " . lfvim " endif " " You may also like to assign a key to this command: " -" nnoremap l :LF +" nnoremap l :LF " function! LF() diff --git a/etc/lfcd.fish b/etc/lfcd.fish new file mode 100644 index 00000000..e43900e3 --- /dev/null +++ b/etc/lfcd.fish @@ -0,0 +1,26 @@ +# Change working dir in fish to last dir in lf on exit (adapted from ranger). +# +# You may put this file to a directory in $fish_function_path variable: +# +# mkdir -p ~/.config/fish/functions +# ln -s "/path/to/lfcd.fish" ~/.config/fish/functions +# +# You may also like to assign a key to this command: +# +# bind \co 'lfcd; commandline -f repaint' +# +# You need to put this in a function called fish_user_key_bindings. + +function lfcd + set tmp (mktemp) + lf -last-dir-path=$tmp $argv + if test -f "$tmp" + set dir (cat $tmp) + rm -f $tmp + if test -d "$dir" + if test "$dir" != (pwd) + cd $dir + end + end + end +end diff --git a/etc/lfcd.sh b/etc/lfcd.sh new file mode 100644 index 00000000..984ba2ca --- /dev/null +++ b/etc/lfcd.sh @@ -0,0 +1,29 @@ +# Change working dir in shell to last dir in lf on exit (adapted from ranger). +# +# You need to either copy the content of this file to your shell rc file +# (e.g. ~/.bashrc) or source this file directly: +# +# LFCD="/path/to/lfcd.sh" +# if [ -f "$LFCD" ]; then +# source "$LFCD" +# fi +# +# You may also like to assign a key to this command: +# +# bind '"\C-o":"lfcd\C-m"' # bash +# bindkey -s '^o' 'lfcd\n' # zsh +# + +lfcd () { + tmp="$(mktemp)" + lf -last-dir-path="$tmp" "$@" + if [ -f "$tmp" ]; then + dir="$(cat "$tmp")" + rm -f "$tmp" + if [ -d "$dir" ]; then + if [ "$dir" != "$(pwd)" ]; then + cd "$dir" + fi + fi + fi +}