config.fish 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. # For ranger, htop and other console progs in Qtile ---------------------------
  2. set -e COLUMNS # -e = --erase
  3. set -e LINES
  4. # disable shortening (~/O/Linux) entirely -------------------------------------
  5. set fish_prompt_pwd_dir_length 0
  6. ###############################################################################
  7. # EXPORTs
  8. ###############################################################################
  9. set HOME (echo /home/$USER)
  10. set GHCUP_INSTALL_BASE_PREFIX "$HOME/.config" # for GHCUP
  11. set GOPATH "$HOME/go"
  12. set -U fish_user_paths $HOME/.local/bin $HOME/Programs/AppImageApplications $fish_user_paths
  13. set PATH $PATH $HOME/.cargo/bin $HOME/.config/vifm/scripts $GHCUP_INSTALL_BASE_PREFIX/.ghcup/bin $HOME/Programs/Android_SDK/platform-tools $GOPATH/bin # PATH for exa in cargo and ...
  14. set EDITOR vim # vim is either a link to nvim or just vim
  15. set VISUAL gvim # gvim is either a link to nvim-qt or just gvim
  16. set TERM xterm-256color
  17. set TERMINAL alacritty
  18. set BROWSER brave
  19. # set MANPAGER "bat man -p" # theme moved to the .config/bat/config
  20. set PAGER bat
  21. set MANPAGER "sh -c 'col -bx | bat -l man -p'" # theme moved to the .config/bat/config
  22. # set -x MANPAGER "sh -c 'col -bx | bat -l man -p'" # $MANPAGER use batcat to read mans
  23. set RANGER_LOAD_DEFAULT_RC FALSE # to avoid loading ranger's config twice
  24. set ANDROID_SDK $HOME"/Programs/Android_SDK"
  25. set XDG_CONFIG_HOME "$HOME/.config"
  26. set XDG_DATA_HOME "$HOME/.local/share"
  27. # set XDG_DATA_DIRS "$HOME/.local/share/flatpak/exports/share" "/var/lib/flatpak/exports/share"
  28. set XDG_CACHE_HOME "$HOME/.cache"
  29. # $EDITOR use Vim to edit crontab ---------------------------------------------
  30. # EDITOR="vim" crontab -e
  31. # select-editor (~/.selected-editor)
  32. set __GIT_PROMPT_DIR ~/.bash-git-prompt # Git autocomplition and prompt
  33. ###############################################################################
  34. # AUTOCOMPLETE AND HIGHLIGHT COLORS
  35. ###############################################################################
  36. # set fish_color_normal brcyan
  37. # set fish_color_autosuggestion '#7d7d7d'
  38. # set fish_color_command brcyan
  39. # set fish_color_error '#ff6c6b'
  40. # set fish_color_param brcyan
  41. set_colorscheme_ayu_Mirage
  42. # set_colorscheme_ayu_Dark
  43. ###############################################################################
  44. # FUNCTIONS
  45. ###############################################################################
  46. function man
  47. command man "$argv" | eval $MANPAGER
  48. end
  49. # SET EITHER DEFAULT EMACS MODE OR VI MODE ------------------------------------
  50. function fish_user_key_bindings
  51. fish_default_key_bindings
  52. # fish_vi_key_bindings
  53. end
  54. function fish_greeting -d "Greeting message on shell session start up"
  55. # Run neofetch
  56. neofetch
  57. end
  58. # Functions needed for !! and !$ ----------------------------------------------
  59. function __history_previous_command
  60. switch (commandline -t)
  61. case "!"
  62. commandline -t $history[1]
  63. commandline -f repaint
  64. case "*"
  65. commandline -i !
  66. end
  67. end
  68. function __history_previous_command_arguments
  69. switch (commandline -t)
  70. case "!"
  71. commandline -t ""
  72. commandline -f history-token-search-backward
  73. case "*"
  74. commandline -i '$'
  75. end
  76. end
  77. # The bindings for !! and !$ --------------------------------------------------
  78. if [ $fish_key_bindings = fish_vi_key_bindings ]
  79. bind -Minsert ! __history_previous_command
  80. bind -Minsert '$' __history_previous_command_arguments
  81. else
  82. bind ! __history_previous_command
  83. bind '$' __history_previous_command_arguments
  84. end
  85. # Function for creating a backup file -----------------------------------------
  86. # ex: backup file.txt
  87. # result: copies file as file.txt.bak
  88. function backup --argument filename
  89. cp $filename $filename.bak
  90. end
  91. # name: bash-git-prompt -------------------------------------------------------
  92. # author: Mariusz Smykuła <mariuszs@gmail.com>
  93. function fish_prompt
  94. # - green lines if the last return command is OK, red otherwise
  95. # - your user name, in red if root or yellow otherwise
  96. # - your hostname, in cyan if ssh or blue otherwise
  97. # - the current path (with prompt_pwd)
  98. # - date +%X
  99. # - the current virtual environment, if any
  100. # - the current git status, if any, with __fish_git_prompt
  101. # - the current battery state, if any, and if your power cable is unplugged, and if you have "acpi"
  102. # - current background jobs, if any
  103. # It goes from:
  104. # ┬─[nim@Hattori:~]─[11:39:00]
  105. # ╰─>$ echo here
  106. # To:
  107. # ┬─[nim@Hattori:~/w/dashboard]─[11:37:14]─[V:django20]─[G:master↑1|●1✚1…1]─[B:85%, 05:41:42 remaining]
  108. # │ 2 15054 0% arrêtée sleep 100000
  109. # │ 1 15048 0% arrêtée sleep 100000
  110. # ╰─>$ echo there
  111. # Colors
  112. # Reset
  113. set ResetColor (set_color normal) # Text Reset
  114. # Regular Colors
  115. set Blue (set_color blue) # Blue
  116. set Green (set_color green) # Green
  117. set Yellow (set_color yellow) # Yellow
  118. set Cyan (set_color cyan)
  119. set Red (set_color red) # Red
  120. set White (set_color white)
  121. # Bold
  122. set BBlue (set_color -o blue)
  123. set BGreen (set_color -o green) # Green
  124. set BYellow (set_color -o yellow) # Yellow
  125. set BCyan (set_color -o brcyan)
  126. set BRed (set_color -o red)
  127. set BWhite (set_color -o white)
  128. set BMagenta (set_color -o magenta) # Purple
  129. set BBlack (set_color -o black) # Black
  130. # # Default values for the appearance of the prompt. Configure at will.
  131. set GIT_PROMPT_PREFIX "("
  132. set GIT_PROMPT_SUFFIX ")"
  133. set GIT_PROMPT_SEPARATOR "|"
  134. set GIT_PROMPT_BRANCH "$BMagenta"
  135. set GIT_PROMPT_STAGED "$Red● "
  136. set GIT_PROMPT_CONFLICTS "$Red✖ "
  137. set GIT_PROMPT_CHANGED "$Blue✚ "
  138. set GIT_PROMPT_REMOTE " "
  139. set GIT_PROMPT_UNTRACKED "…"
  140. set GIT_PROMPT_STASHED "⚑ "
  141. set GIT_PROMPT_CLEAN "$BGreen✔"
  142. set -q __fish_git_prompt_showupstream
  143. or set -g __fish_git_prompt_showupstream auto
  144. function _nim_prompt_wrapper
  145. set retc $argv[1]
  146. set field_name $argv[2]
  147. set field_value $argv[3]
  148. set_color normal
  149. set_color $retc
  150. # echo -n '─'
  151. set_color -o green
  152. echo -n '['
  153. set_color normal
  154. test -n $field_name
  155. and echo -n $field_name:
  156. set_color $retc
  157. echo -n $field_value
  158. set_color -o green
  159. echo -n ']'
  160. end
  161. and set retc green
  162. or set retc red
  163. set_color $retc
  164. echo
  165. # echo -n '┬─'
  166. set_color -o green
  167. echo -n [
  168. if test "$USER" = root -o "$USER" = toor
  169. set_color -o red
  170. else
  171. set_color -o yellow
  172. end
  173. echo -n $USER
  174. set_color -o white
  175. echo -n @
  176. if [ -z "$SSH_CLIENT" ]
  177. set_color -o blue
  178. else
  179. set_color -o cyan
  180. end
  181. echo -n (prompt_hostname):
  182. set_color -o white
  183. echo -n (prompt_pwd)
  184. set_color -o green
  185. echo -n ']'
  186. # Date
  187. # _nim_prompt_wrapper $retc '' (date "+%I:%M %p")
  188. _nim_prompt_wrapper $retc '' (date "+%H:%M")
  189. # Virtual Environment
  190. # set -q VIRTUAL_ENV
  191. # and _nim_prompt_wrapper $retc V (basename "$VIRTUAL_ENV")
  192. # git
  193. set -e __CURRENT_GIT_STATUS
  194. set gitstatus "$__GIT_PROMPT_DIR/gitstatus.py"
  195. # set _GIT_STATUS (python $gitstatus)
  196. set _GIT_STATUS (python3 $gitstatus)
  197. set __CURRENT_GIT_STATUS $_GIT_STATUS
  198. set __CURRENT_GIT_STATUS_PARAM_COUNT (count $__CURRENT_GIT_STATUS)
  199. if not test 0 -eq $__CURRENT_GIT_STATUS_PARAM_COUNT
  200. set GIT_BRANCH $__CURRENT_GIT_STATUS[1]
  201. set GIT_REMOTE "$__CURRENT_GIT_STATUS[2]"
  202. if contains "." "$GIT_REMOTE"
  203. set -e GIT_REMOTE
  204. end
  205. set GIT_STAGED $__CURRENT_GIT_STATUS[3]
  206. set GIT_CONFLICTS $__CURRENT_GIT_STATUS[4]
  207. set GIT_CHANGED $__CURRENT_GIT_STATUS[5]
  208. set GIT_UNTRACKED $__CURRENT_GIT_STATUS[6]
  209. set GIT_STASHED $__CURRENT_GIT_STATUS[7]
  210. set GIT_CLEAN $__CURRENT_GIT_STATUS[8]
  211. end
  212. if test -n "$__CURRENT_GIT_STATUS"
  213. set STATUS "$GIT_PROMPT_BRANCH$GIT_BRANCH$ResetColor"
  214. if set -q GIT_REMOTE
  215. set STATUS "$STATUS$GIT_PROMPT_REMOTE$GIT_REMOTE$ResetColor"
  216. end
  217. set STATUS "$STATUS$GIT_PROMPT_SEPARATOR"
  218. if [ $GIT_STAGED != 0 ]
  219. set STATUS "$STATUS$GIT_PROMPT_STAGED$GIT_STAGED$ResetColor"
  220. end
  221. if [ $GIT_CONFLICTS != 0 ]
  222. set STATUS "$STATUS$GIT_PROMPT_CONFLICTS$GIT_CONFLICTS$ResetColor"
  223. end
  224. if [ $GIT_CHANGED != 0 ]
  225. set STATUS "$STATUS$GIT_PROMPT_CHANGED$GIT_CHANGED$ResetColor"
  226. end
  227. if [ "$GIT_UNTRACKED" != 0 ]
  228. set STATUS "$STATUS$GIT_PROMPT_UNTRACKED$GIT_UNTRACKED$ResetColor"
  229. end
  230. if [ "$GIT_STASHED" != 0 ]
  231. set STATUS "$STATUS$GIT_PROMPT_STASHED$GIT_STASHED$ResetColor"
  232. end
  233. if [ "$GIT_CLEAN" = 1 ]
  234. set STATUS "$STATUS$GIT_PROMPT_CLEAN"
  235. end
  236. set STATUS "$STATUS$ResetColor"
  237. set prompt_git "$STATUS"
  238. else
  239. set prompt_git ""
  240. end
  241. # set prompt_git (__fish_git_prompt | string trim -c ' ()')
  242. test -n "$prompt_git"
  243. and _nim_prompt_wrapper $retc G $prompt_git
  244. # Battery status
  245. type -q acpi
  246. and test (acpi -a 2> /dev/null | string match -r off)
  247. and _nim_prompt_wrapper $retc B (acpi -b | cut -d' ' -f 4-)
  248. # New line
  249. echo
  250. # Background jobs
  251. set_color normal
  252. for job in (jobs)
  253. set_color $retc
  254. # echo -n '│ '
  255. set_color brown
  256. echo $job
  257. end
  258. set_color normal
  259. set_color $retc
  260. # echo -n '╰─>'
  261. if test "$USER" = root -o "$USER" = toor
  262. set_color -o red
  263. # echo -n '# '
  264. echo -n ' >_ '
  265. else
  266. set_color -o yellow
  267. # echo -n '$ '
  268. echo -n ' >_ '
  269. end
  270. set_color normal
  271. end
  272. ###############################################################################
  273. # ALIASES
  274. ###############################################################################
  275. # alias ls='ls --color=auto'
  276. # alias ll='ls -l'
  277. # alias ll='ls -lh'
  278. # alias la='ls -la'
  279. # alias la='ls -lah'
  280. # alias lf='ls -lFh'
  281. alias lse='exa -g --color=always --group-directories-first'
  282. alias lle='lse -l'
  283. alias ls='lsd --group-dirs=first'
  284. alias ll='lsd --blocks=permission,links,user,group,size,date,name --group-dirs=first --date="+%d %b %H:%M"'
  285. alias la='ll -a'
  286. alias tree='lsd --tree'
  287. # alias bat='bat --theme gruvbox-dark' # theme moved to the .config/bat/config
  288. alias grep='grep --color=auto'
  289. alias fgrep='fgrep --color=auto'
  290. alias egrep='egrep --color=auto'
  291. alias ifconfig=/sbin/ifconfig
  292. # confirm before overwriting something ----------------------------------------
  293. alias cp="cp -i"
  294. alias mv='mv -i'
  295. alias rm='rm -i'
  296. # switch between shells -------------------------------------------------------
  297. alias tobash="sudo chsh $USER -s /usr/bin/env bash && echo 'Now log out.'"
  298. alias tozsh="sudo chsh $USER -s /usr/bin/env zsh && echo 'Now log out.'"
  299. alias tofish="sudo chsh $USER -s /usr/bin/env fish && echo 'Now log out.'"
  300. # navigation ------------------------------------------------------------------
  301. alias ..='cd ..'
  302. alias ...='cd ../..'
  303. alias .3='cd ../../..'
  304. alias .4='cd ../../../..'
  305. alias .5='cd ../../../../..'
  306. # get top process eating memory -----------------------------------------------
  307. alias psmem='ps auxf | sort -nr -k 4'
  308. alias psmem10='ps auxf | sort -nr -k 4 | head -10'
  309. # get top process eating cpu --------------------------------------------------
  310. alias pscpu='ps auxf | sort -nr -k 3'
  311. alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
  312. # git -------------------------------------------------------------------------
  313. alias config='/usr/bin/git --git-dir=$HOME/.dotfiles.git --work-tree=$HOME'
  314. # run some programs -----------------------------------------------------------
  315. alias v='vim'
  316. alias f='ranger'
  317. alias vf='vifm'
  318. alias emacs="emacsclient -c -a 'emacs'"
  319. ###############################################################################
  320. # Source
  321. ###############################################################################
  322. # asdf manager ----------------------------------------------------------------
  323. # source ~/.asdf/asdf.fish
  324. # opam configuration ----------------------------------------------------------
  325. source /home/alexander/.opam/opam-init/init.fish >/dev/null 2>/dev/null; or true
  326. # Fuzzy finder ----------------------------------------------------------------
  327. # source /usr/share/fzf/key-bindings.fish
  328. ### key-bindings.fish ###
  329. # ____ ____
  330. # / __/___ / __/
  331. # / /_/_ / / /_
  332. # / __/ / /_/ __/
  333. # /_/ /___/_/ key-bindings.fish
  334. #
  335. # - $FZF_TMUX_OPTS
  336. # - $FZF_CTRL_T_COMMAND
  337. # - $FZF_CTRL_T_OPTS
  338. # - $FZF_CTRL_R_OPTS
  339. # - $FZF_ALT_C_COMMAND
  340. # - $FZF_ALT_C_OPTS
  341. status is-interactive; or exit 0
  342. # Key bindings
  343. # ------------
  344. function fzf_key_bindings
  345. function __fzf_defaults
  346. # $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
  347. # $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
  348. test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
  349. echo "--height $FZF_TMUX_HEIGHT --bind=ctrl-z:ignore" $argv[1]
  350. command cat "$FZF_DEFAULT_OPTS_FILE" 2> /dev/null
  351. echo $FZF_DEFAULT_OPTS $argv[2]
  352. end
  353. # Store current token in $dir as root for the 'find' command
  354. function fzf-file-widget -d "List files and folders"
  355. set -l commandline (__fzf_parse_commandline)
  356. set -lx dir $commandline[1]
  357. set -l fzf_query $commandline[2]
  358. set -l prefix $commandline[3]
  359. test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
  360. begin
  361. set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path --walker-root='$dir'" "$FZF_CTRL_T_OPTS")
  362. set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND"
  363. set -lx FZF_DEFAULT_OPTS_FILE ''
  364. eval (__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
  365. end
  366. if [ -z "$result" ]
  367. commandline -f repaint
  368. return
  369. else
  370. # Remove last token from commandline.
  371. commandline -t ""
  372. end
  373. for i in $result
  374. commandline -it -- $prefix
  375. commandline -it -- (string escape $i)
  376. commandline -it -- ' '
  377. end
  378. commandline -f repaint
  379. end
  380. function fzf-history-widget -d "Show command history"
  381. test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
  382. begin
  383. set -l FISH_MAJOR (echo $version | cut -f1 -d.)
  384. set -l FISH_MINOR (echo $version | cut -f2 -d.)
  385. # merge history from other sessions before searching
  386. if test -z "$fish_private_mode"
  387. builtin history merge
  388. end
  389. # history's -z flag is needed for multi-line support.
  390. # history's -z flag was added in fish 2.4.0, so don't use it for versions
  391. # before 2.4.0.
  392. if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ];
  393. if type -P perl > /dev/null 2>&1
  394. set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
  395. set -lx FZF_DEFAULT_OPTS_FILE ''
  396. builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | command perl -pe 's/^\d*\t//' | read -lz result
  397. and commandline -- $result
  398. else
  399. set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "--scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
  400. set -lx FZF_DEFAULT_OPTS_FILE ''
  401. builtin history -z | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | read -lz result
  402. and commandline -- $result
  403. end
  404. else
  405. builtin history | eval (__fzfcmd) -q '(commandline)' | read -l result
  406. and commandline -- $result
  407. end
  408. end
  409. commandline -f repaint
  410. end
  411. function fzf-cd-widget -d "Change directory"
  412. set -l commandline (__fzf_parse_commandline)
  413. set -lx dir $commandline[1]
  414. set -l fzf_query $commandline[2]
  415. set -l prefix $commandline[3]
  416. test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
  417. begin
  418. set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path --walker-root='$dir'" "$FZF_ALT_C_OPTS")
  419. set -lx FZF_DEFAULT_OPTS_FILE ''
  420. set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND"
  421. eval (__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
  422. if [ -n "$result" ]
  423. cd -- $result
  424. # Remove last token from commandline.
  425. commandline -t ""
  426. commandline -it -- $prefix
  427. end
  428. end
  429. commandline -f repaint
  430. end
  431. function __fzfcmd
  432. test -n "$FZF_TMUX"; or set FZF_TMUX 0
  433. test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
  434. if [ -n "$FZF_TMUX_OPTS" ]
  435. echo "fzf-tmux $FZF_TMUX_OPTS -- "
  436. else if [ $FZF_TMUX -eq 1 ]
  437. echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
  438. else
  439. echo "fzf"
  440. end
  441. end
  442. bind \cr fzf-history-widget
  443. if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
  444. bind \ct fzf-file-widget
  445. end
  446. if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
  447. bind \ec fzf-cd-widget
  448. end
  449. if bind -M insert > /dev/null 2>&1
  450. bind -M insert \cr fzf-history-widget
  451. if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
  452. bind -M insert \ct fzf-file-widget
  453. end
  454. if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
  455. bind -M insert \ec fzf-cd-widget
  456. end
  457. end
  458. function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'
  459. set -l commandline (commandline -t)
  460. # strip -option= from token if present
  461. set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)
  462. set commandline (string replace -- "$prefix" '' $commandline)
  463. # eval is used to do shell expansion on paths
  464. eval set commandline $commandline
  465. if [ -z $commandline ]
  466. # Default to current directory with no --query
  467. set dir '.'
  468. set fzf_query ''
  469. else
  470. set dir (__fzf_get_dir $commandline)
  471. if [ "$dir" = "." -a (string sub -l 1 -- $commandline) != '.' ]
  472. # if $dir is "." but commandline is not a relative path, this means no file path found
  473. set fzf_query $commandline
  474. else
  475. # Also remove trailing slash after dir, to "split" input properly
  476. set fzf_query (string replace -r "^$dir/?" -- '' "$commandline")
  477. end
  478. end
  479. echo $dir
  480. echo $fzf_query
  481. echo $prefix
  482. end
  483. function __fzf_get_dir -d 'Find the longest existing filepath from input string'
  484. set dir $argv
  485. # Strip all trailing slashes. Ignore if $dir is root dir (/)
  486. if [ (string length -- $dir) -gt 1 ]
  487. set dir (string replace -r '/*$' -- '' $dir)
  488. end
  489. # Iteratively check if dir exists and strip tail end of path
  490. while [ ! -d "$dir" ]
  491. # If path is absolute, this can keep going until ends up at /
  492. # If path is relative, this can keep going until entire input is consumed, dirname returns "."
  493. set dir (dirname -- "$dir")
  494. end
  495. echo $dir
  496. end
  497. end
  498. ### end: key-bindings.fish ###
  499. fzf_key_bindings