add ability to convert $HOME to ~/ when saving and updating projects
This commit is contained in:
parent
a702041479
commit
cd14282e5e
2 changed files with 22 additions and 11 deletions
|
@ -190,6 +190,14 @@ changed with `fzf_tmux_height` option. `fzf_tmux_height_file_preview` option is
|
|||
used to control height of the split when you do file searching with file-preview
|
||||
turned on.
|
||||
|
||||
### Projects
|
||||
**fzf.kak** can store and load your projects. For that It creates a hidden file
|
||||
in your `%val{config}` called `.fzf-projects`. You can change the location of
|
||||
this file and its name with `fzf_project_file` option. You also can choose which
|
||||
method to use when storing projects. You can either convert your `$HOME` to `~/`
|
||||
or use plain `$HOME` in your path. This behavior is configured with
|
||||
`fzf_project_use_tilda` option, which accepts `true` and `false` values.
|
||||
|
||||
## `fzf` command
|
||||
`fzf` command can be used from prompt mode and for [scripting][20]. It supports
|
||||
these arguments:
|
||||
|
|
|
@ -17,23 +17,25 @@ map global fzf-project -docstring "save current path as project" 's' '<esc>: fzf
|
|||
map global fzf-project -docstring "update project" 'u' '<esc>: fzf-update-project-path<ret>'
|
||||
map global fzf-project -docstring "delete project from project list" 'd' '<esc>: fzf-delete-project<ret>'
|
||||
|
||||
declare-option -docstring "file where saved projects are stored" str fzf_projects_file "%val{config}/.fzf-projects"
|
||||
declare-option -docstring "file where saved projects are stored" str fzf_project_file "%val{config}/.fzf-projects"
|
||||
declare-option -docstring %sh{ printf "%s\n" "use ~/ instead of $HOME" } bool fzf_project_use_tilda false
|
||||
|
||||
define-command -hidden fzf-project %{ evaluate-commands %sh{
|
||||
if [ -s $kak_opt_fzf_projects_file ]; then
|
||||
if [ -s $kak_opt_fzf_project_file ]; then
|
||||
printf '%s\n' "info -title %{fzf open project} %{Change the server's working directory to selected project}"
|
||||
printf "%s\n" "fzf -kak-cmd change-directory -items-cmd %{cat $kak_opt_fzf_projects_file} -preview-cmd %{$preview} -post-action fzf-file -filter %{sed 's/.*: //'}"
|
||||
printf "%s\n" "fzf -kak-cmd change-directory -items-cmd %{cat $kak_opt_fzf_project_file} -preview-cmd %{$preview} -post-action fzf-file -filter %{sed 's/.*: //'}"
|
||||
else
|
||||
printf "%s\n" "echo -markup %{{Information}No projects defined in '$kak_opt_fzf_projects_file'}"
|
||||
printf "%s\n" "echo -markup %{{Information}No project defined in '$kak_opt_fzf_project_file'}"
|
||||
fi
|
||||
}}
|
||||
|
||||
define-command -hidden fzf-save-path-as-project %{ prompt "Project's name: " %{ evaluate-commands %sh{
|
||||
mkdir -p "${kak_opt_fzf_projects_file%/*}"
|
||||
mkdir -p "${kak_opt_fzf_project_file%/*}"
|
||||
tmp=$(mktemp "${TMPDIR:-/tmp}/fzf-project.XXXXXXX")
|
||||
project=$(grep "$kak_text: " $kak_opt_fzf_projects_file)
|
||||
project=$(grep "$kak_text: " $kak_opt_fzf_project_file)
|
||||
if [ -z "${project}" ]; then
|
||||
printf "%s: %s\n" "$kak_text" "$(pwd)" >> $kak_opt_fzf_projects_file
|
||||
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s($HOME)(~)")
|
||||
printf "%s: %s\n" "$kak_text" "${project_path}" >> $kak_opt_fzf_project_file
|
||||
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '$kak_text'}"
|
||||
else
|
||||
project="$kak_text"
|
||||
|
@ -50,7 +52,7 @@ define-command -hidden fzf-save-path-as-project %{ prompt "Project's name: " %{
|
|||
}}}
|
||||
|
||||
define-command -hidden fzf-update-project-path %{
|
||||
prompt -shell-script-candidates %{ perl -n -e '/^([^:]+)/ && print "$1\n"' $kak_opt_fzf_projects_file } "Project to update: " %{
|
||||
prompt -shell-script-candidates %{ perl -n -e '/^([^:]+)/ && print "$1\n"' $kak_opt_fzf_project_file } "Project to update: " %{
|
||||
fzf-update-project-path-impl %val{text}
|
||||
echo -markup "{Information}'%val{text}' project updated"
|
||||
}
|
||||
|
@ -58,14 +60,15 @@ define-command -hidden fzf-update-project-path %{
|
|||
|
||||
define-command fzf-update-project-path-impl -params 1 %{ nop %sh{
|
||||
tmp=$(mktemp "${TMPDIR:-/tmp}/fzf-project.XXXXXXX")
|
||||
perl -pe "s(\Q$1: \E.*)($1: $(pwd))" "${kak_opt_fzf_projects_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_projects_file}"
|
||||
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s($HOME)(~)")
|
||||
perl -pe "s(\Q$1: \E.*)($1: ${project_path})" "${kak_opt_fzf_project_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_project_file}"
|
||||
rm -rf ${tmp}
|
||||
}}
|
||||
|
||||
define-command -hidden fzf-delete-project %{
|
||||
prompt -shell-script-candidates %{ perl -n -e '/^([^:]+)/ && print "$1\n"' $kak_opt_fzf_projects_file } "Project to delete: " %{ nop %sh{
|
||||
prompt -shell-script-candidates %{ perl -n -e '/^([^:]+)/ && print "$1\n"' $kak_opt_fzf_project_file } "Project to delete: " %{ nop %sh{
|
||||
tmp=$(mktemp "${TMPDIR:-/tmp}/fzf-project.XXXXXXX")
|
||||
perl -pe "s(\Q$kak_text: \E.*\n)()" "${kak_opt_fzf_projects_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_projects_file}"
|
||||
perl -pe "s(\Q$kak_text: \E.*\n)()" "${kak_opt_fzf_project_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_project_file}"
|
||||
rm -rf ${tmp}
|
||||
}}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue