aboutsummaryrefslogtreecommitdiff
path: root/config/lf/lfrc
blob: 32f21f93ee24aacb124efedae943264938b79c59 (plain) (blame)
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
set hidden true
set drawbox true
set icons true
set ignorecase true
set relativenumber true
set ratios 2:3
set dirpreviews false

set preview true
set previewer ~/nixos/config/lf/previewer.sh
set cleaner ~/nixos/config/lf/cleaner.sh
set cursorpreviewfmt "\033[7m"

cmd open_internal ${{
    case $(file --mime-type "$f" -bL) in
        text/*|application/json) $EDITOR "$fx" ;;
        video/*|application/pdf) ~/scripts/bin/open "$f" >/dev/null 2>&1 & ;;
        *) for f in "$fx"; do
          ~/scripts/bin/open "$f" 2>/dev/null
        done ;;
    esac;
    disown 2>/dev/null;
}}
cmd open open_internal

cmd mkdir ${{
  printf "Directory Name: "
  read ans
  mkdir $ans
}}

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

cmd show_images ${{
  if [ "$(echo "$fx" | wc -l)" = "1" ]; then
    sxiv $(dirname "$fx") &
  else
    sxiv $fx &
  fi;
}}

cmd unzip_zip ${{
  unzip $f;
}}

cmd unzip_7z ${{
  nix-shell -p p7zip --run '7z x $f';
}}

cmd unzip_rar ${{
  NIXPKGS_ALLOW_UNFREE=1 nix-shell -p unrar --run 'unrar x $f';
}}

cmd unpack ${{
  typ=$(file --mime-type "$f" -bL);
  case $(typ) in
    application/zip)
      unzip "$f"
    ;;
    application/x-tar|application/gzip)
      tar xzf "$f"
    ;;
    application/x-7z-compressed)
      nix-shell -p p7zip --run "7z x '$f'"
    ;;
    application/vnd.rar)
      NIXPKGS_ALLOW_UNFREE=1 nix-shell -p unrar --run "unrar x '$f'"
    ;;
    *)
      lf -remote "send $id echoerr 'Unknown archive type: $typ'";
    ;;
  esac
}}

cmd sudo_delete ${{
  echo "Deleting $f..."
  sudo --reset-timestamp rm -rf "$f"
}}

# Unset old keys
map w
map m
map n
map p
map "'"
map '"'
map d}}
map c
map e
map d

# TODO: fzf search through files

# fzf search through directories
cmd fuzzy_search_dirs ${{
  dir=$(find . -type d | fzf);
  if ! [ -z "$dir" ]; then
    lf -remote "send $id cd $dir";
  fi
}}

# Mutations
map dd      delete
map sdd     sudo_delete
map p       paste
map x       cut
map y       copy
map mf      mkfile
map md      mkdir

# View changes
map <enter> open_internal
map <c-o>   open_internal
map si      show_images
map .       :set hidden!
map st      :set sortby time; set info time
map ss      :set sortby size; set info size

# Search next/prev
map <tab> search-next
map <backtab> search-prev

# Traversal keys
map \\f   fuzzy_search_dirs
map gdl   cd ~/Downloads
map gmd   cd /media
map gdm   cd ~/Downloads/music
map gdv   cd ~/dev
map gdp   cd ~/dump
map gp    cd ~/Pictures
map gsc   cd ~/Pictures/screenshots
map gmnt  cd /run/media/imsohexy
map gdc   cd ~/Documents
map gkb   cd /run/user/1000/keybase/kbfs