tenseleyflow/ndotfiles / fc2bb4b

Browse files

even more fish functions

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
fc2bb4b01c978721586b1380d938ea7299feb513
Parents
c68995a
Tree
08dfb60

5 changed files

StatusFile+-
A fish/functions/cdf.fish 6 0
A fish/functions/clipf.fish 8 0
A fish/functions/f.fish 6 0
A fish/functions/fish_user_key_bindings.fish 3 0
A fish/functions/open_at_line.fish 33 0
fish/functions/cdf.fishadded
@@ -0,0 +1,6 @@
1
+## jump to dir
2
+#
3
+function cdf
4
+    set -l dir (fd --type d --hidden --follow --exclude .git | fzf)
5
+    test -n "$dir"; and cd "$dir"
6
+end
fish/functions/clipf.fishadded
@@ -0,0 +1,8 @@
1
+## fuzzy pick from clipboard history, copy
2
+#
3
+function clipf
4
+    type -q cliphist; or begin; echo "cliphist not installed"; return 1; end
5
+    set -l id (cliphist list | fzf --tac --preview 'cliphist decode {} | sed -n "1,200p"')
6
+    test -n "$id"; or return
7
+    cliphist decode $id | wl-copy
8
+end
fish/functions/f.fishadded
@@ -0,0 +1,6 @@
1
+## preview file, open in editor
2
+#
3
+function f
4
+    set -l files (_fzf --multi)
5
+    test -n "$files"; and $EDITOR $files
6
+end
fish/functions/fish_user_key_bindings.fishadded
@@ -0,0 +1,3 @@
1
+function fish_user_key_bindings
2
+  fzf_key_bindings
3
+end
fish/functions/open_at_line.fishadded
@@ -0,0 +1,33 @@
1
+## open file at a specific line in editor (agnostic. sorta)
2
+#
3
+function open_at_line
4
+    set -l file $argv[1]; set -l line $argv[2]
5
+    if test -z "$file" -o -z "$line"
6
+        echo "usage: open_at_line <file> <line>"; return 1
7
+    end
8
+
9
+    # Extract the base command from $EDITOR ("code --wait" -> "code")
10
+    set -l editor_base (basename -- (string split ' ' -- $EDITOR)[1])
11
+
12
+    switch $editor_base
13
+        case 'code' 'code-insiders'
14
+            # VS Code: --goto file:line
15
+            $EDITOR -g "$file":$line
16
+
17
+        case 'hx'
18
+            # Helix understands path:row[:col] in recent builds; fall back to +LINE
19
+            hx "$file":$line; or hx +$line "$file"
20
+
21
+        case 'micro'
22
+            # Micro: enable parsecursor so file:line works reliably
23
+            micro --parsecursor "$file":$line
24
+
25
+        case 'nvim' 'vim' 'vi' 'kak' 'nano'
26
+            # Many TUI editors accept +LINE
27
+            $EDITOR +$line "$file"
28
+
29
+        case '*'
30
+            # Generic fallback used by many editors (sed-like)
31
+            $EDITOR +$line "$file"
32
+    end
33
+end