From 1812d7b9de476f44545c3bf98b32661d36cd3e9b Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Sun, 7 Apr 2019 19:11:02 +0300 Subject: [PATCH] add -force switch #52 --- rc/modules/fzf-project.kak | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rc/modules/fzf-project.kak b/rc/modules/fzf-project.kak index 0b9617f..e2b96dc 100644 --- a/rc/modules/fzf-project.kak +++ b/rc/modules/fzf-project.kak @@ -72,8 +72,14 @@ define-command -hidden fzf-save-path-as-project-no-prompt %{ evaluate-commands % }} define-command -docstring \ -"fzf-add-project []: add given to project list with given . If name omitted basename of the project is used for the name" \ +"fzf-add-project [] []: add given to project list with given . If name omitted basename of the project is used for the name +Switches: + -force: overwrite project if exists without asking" \ fzf-add-project -file-completion -params 1..2 %{ evaluate-commands %sh{ + if [ "$1" = "-force" ]; then + force="true" + shift + fi # portable version of `basename' base() { filename=$1 @@ -92,10 +98,9 @@ fzf-add-project -file-completion -params 1..2 %{ evaluate-commands %sh{ mkdir -p "${kak_opt_fzf_project_file%/*}" project_path="$1" project_name="$2" - echo "echo -debug %{'$(base ${project_path})'}" [ -z "${project_name}" ] && project_name=$(base ${project_path}) exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file}) - if [ -z "${exists}" ]; then + if [ -z "${exists}" ] || [ "${force}" = "true" ]; then [ "${kak_opt_fzf_project_use_tilda}" = "false" ] || project_path=$(printf "%s\n" ${project_path} | perl -pe "s(${HOME})(~)") printf "%s: %s\n" "${project_name}" "${project_path}" >> ${kak_opt_fzf_project_file} printf "%s\n" "echo -markup %{{Information}saved '${project_path}' project as '${project_name}'}"