aboutsummaryrefslogtreecommitdiff
path: root/.config/lf/lfrc
blob: 029cc8f40d961980c0acd59b3746f42990a8c0d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# Basic Settings
set previewer ~/.config/lf/preview
set preview true
# set drawbox true
# set icons true
set ignorecase true
set scrolloff 1
set shell zsh

# unmap keys
map y
map d
map m

# keymappings
# rename
map C rename # at the end
map c push C<a-b><a-b><a-f>
map <c-c> push C<c-u> # new rename
map B bulk-rename # fix this

# lf commands
map H set hidden!
map <c-r> reload

# cut/copy/paste
map p paste
map yy copy
map dd cut
map D delete

# new files/directories
map md push :mkdir<space>
map mf push :mkfile<space>
map mF push :touch<space>

# opening files
map o push :open-with<space>
map L open_ext
map P share

# selecting files/globs
map t toggle

# custom commands
cmd open ${{
  case $(file --mime-type "$f" -bL) in
    text/*|application/json) $EDITOR "$f";;
    *) xdg-open "$f" ;;
  esac
}}

# open in another terminal
cmd open_ext ${{
  case $(file --mime-type "$f" -bL) in
    text/*|application/json) $TERMINAL "-e" $EDITOR "$f";;
    *) xdg-open "$f" ;;
  esac
}}

# cmd mkdir ${{
#   set -f
#   printf "Directory Name: "
#   read ans
#   mkdir $ans
# }}

# cmd mkfile ${{
#   printf "File Name: "
#   read ans
#   $EDITOR $ans
# }}

# cmd mkdir %mkdir "$@"
cmd mkdir %{{
    IFS=" "
    mkdir -p -- "$*"
    lf -remote "send $id select \"$*\""
}}
cmd mkfile %nvim "$@"
# cmd touch %touch "$@"
cmd touch %{{
    IFS=" "
    touch "$*"
    lf -remote "send $id select \"$*\""
}}

cmd chmod ${{
  printf "Mode Bits: "
  read ans

  for file in "$fx"
  do
    chmod $ans $file
  done

  lf -remote 'send reload'
}}

cmd open-with %"$@" $fx
cmd share $curl -F"file=@$fx" https://0x0.st | xclip -selection c

# bulk rename non-hidden or selected files
# cmd bulk-rename ${{
#     old="$(mktemp)"
#     new="$(mktemp)"
#     [ -n "$fs" ] && fs="$(ls)"
#     printf '%s\n' "$fs" >"$old"
#     printf '%s\n' "$fs" >"$new"
#     $EDITOR "$new"
#     [ "$(wc -l "$new")" -ne "$(wc -l "$old")" ] && exit
#     paste "$old" "$new" | while IFS= read -r names; do
#         src="$(printf '%s' "$names" | cut -f1)"
#         dst="$(printf '%s' "$names" | cut -f2)"
#         if [ "$src" = "$dst" ] || [ -e "$dst" ]; then
#             continue
#         fi
#         mv -- "$src" "$dst"
#     done
#     rm -- "$old" "$new"
#     lf -remote "send $id unselect"
# }}

# override paste with cp-p
cmd paste $cp-p --lf-paste $id

# archive bindings
cmd unarchive ${{
  case "$f" in
      *.zip) unzip "$f" ;;
      *.tar.gz) tar -xzvf "$f" ;;
      *.tar.bz2) tar -xjvf "$f" ;;
      *.tar) tar -xvf "$f" ;;
      *) echo "Unsupported format" ;;
  esac
}}

cmd zip %zip -r "$f" "$f"
cmd tar %tar cvf "$f.tar" "$f"
cmd targz %tar cvzf "$f.tar.gz" "$f"
cmd tarbz2 %tar cjvf "$f.tar.bz2" "$f"

# archive mappings
map az zip
map at tar
map ag targz
map ab targz
map au unarchive

# this runs on each directory change
cmd on-cd &{{
    # display git repository status in your prompt
    source /usr/share/git/completion/git-prompt.sh
    GIT_PS1_SHOWDIRTYSTATE=auto
    GIT_PS1_SHOWSTASHSTATE=auto
    GIT_PS1_SHOWUNTRACKEDFILES=auto
    GIT_PS1_SHOWUPSTREAM=auto
    GIT_PS1_COMPRESSSPARSESTATE=auto
    git=$(__git_ps1 " [GIT BRANCH:> %s]") || true
    fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[33;1m$git\033[0m"
    lf -remote "send $id set promptfmt \"$fmt\""
    
    # update window title
    printf "\033]0; $PWD\007" > /dev/tty
}}

# set number of columns depending
# on window size on startup
# %{{
#     w=$(tput cols)
#     if [ $w -le 80 ]; then
#         lf -remote "send $id set ratios 1:2"
#     elif [ $w -le 160 ]; then
#         lf -remote "send $id set ratios 1:2:3"
#     else
#         lf -remote "send $id set ratios 1:2:3:5"
#     fi
# }}