diff options
author | Yoonki Park <yoonki.park@samsung.com> | 2014-04-02 18:23:38 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.vlan103.tizen.org> | 2014-04-02 18:23:38 -0700 |
commit | 58bbfa807216b2c571989fca7bff5411a7075f5c (patch) | |
tree | 781e0d4916ac88d97a7358ee5009fb7d4cecee23 | |
parent | fe5f8099903a86cf4c154ef3638a57848037a578 (diff) | |
parent | c20bb912f4f715ecad4405cfdf4170984cf9c2ff (diff) | |
download | sdb-58bbfa807216b2c571989fca7bff5411a7075f5c.tar.gz sdb-58bbfa807216b2c571989fca7bff5411a7075f5c.tar.bz2 sdb-58bbfa807216b2c571989fca7bff5411a7075f5c.zip |
Merge "SDB: Fixed a bug where completing remote path automatically is not worked." into tizen
-rw-r--r-- | package/.sdb-completion.bash | 21 | ||||
-rw-r--r-- | src/auto_complete.c | 25 |
2 files changed, 37 insertions, 9 deletions
diff --git a/package/.sdb-completion.bash b/package/.sdb-completion.bash index d58fc0b..7623a06 100644 --- a/package/.sdb-completion.bash +++ b/package/.sdb-completion.bash @@ -1,10 +1,13 @@ _sdb() { - #sdb path is defined in PATH environment variable - COMPREPLY=() + #check if the input is local or remote path. + INPUT_IS_PATH=0 + #sdb path is defined in PATH environment variable SDB_PATH=$(eval eval echo \$\{COMP_WORDS\[0\]\}) + COMPREPLY=() + if [ ! -f ${SDB_PATH} ]; then return 0; @@ -14,6 +17,13 @@ _sdb() ARGS="autocomplete,${COMP_CWORD}" local IFS=$',' + + if [ -n ${COMP_WORDS[1]} ]; then + if [ "${COMP_WORDS[1]}" == "push" ] || [ "${COMP_WORDS[1]}" == "pull" ]; then + INPUT_IS_PATH=1 + fi + fi + for ((i=1; i < $((${COMP_CWORD} + 1)) ; i++)) do #processing for echo options @@ -30,9 +40,12 @@ _sdb() next=($("${SDB_PATH}" ${ARGS})) local IFS=$'\n' COMPREPLY=(${next}) -# COMPREPLY=($(compgen -W "${next}" -- ${cur})) + + if [ $INPUT_IS_PATH == 0 ]; then + COMPREPLY=( "${COMPREPLY[@]/%/ }" ) #add trailing space to each + fi return 0 } -complete -o filenames -F _sdb sdb +complete -o nospace -F _sdb sdb diff --git a/src/auto_complete.c b/src/auto_complete.c index f336503..b56d33b 100644 --- a/src/auto_complete.c +++ b/src/auto_complete.c @@ -34,6 +34,7 @@ #include "strutils.h" #include "auto_complete.h" #include "file_sync_service.h" +#include "log.h" static int parse_opt(int argc, char** argv); static int parse_cmd(int argc, char** argv); @@ -60,6 +61,7 @@ static int COMPLETE_FLAG = 0; static FILE* AC_STDOUT = NULL; static FILE* AC_STDERR = NULL; static const char IFS = '\n'; +static const char PATH_SEPARATOR = '\/'; static struct ac_element emulator_short = { .keyword = "-e", @@ -501,6 +503,7 @@ static void print_local_dirlist(char* src_dir, char** not_complete_char) { goto finalize; } struct dirent* de; + struct stat statbuf; while((de = readdir(d))) { char* file_name = de->d_name; @@ -517,6 +520,13 @@ static void print_local_dirlist(char* src_dir, char** not_complete_char) { char src_full_path[PATH_MAX]; append_file(src_full_path, src_dir, file_name, PATH_MAX); + // get file stat + if(stat(src_full_path, &statbuf) == -1) + { + fprintf(stderr, "error: exception occurred while getting file stat: %s\n", src_full_path); + goto finalize; + } + char* src_ptr = src_full_path; if(pwd_flag) { src_ptr += 2; @@ -526,9 +536,12 @@ static void print_local_dirlist(char* src_dir, char** not_complete_char) { fprintf(AC_STDOUT, "%s%c", src_ptr, IFS); } else { - int len = strnlen(not_complete_char[0], 255); + int len = strnlen(not_complete_char[0], PATH_MAX); if(!strncmp(not_complete_char[0], src_ptr, len)) { - fprintf(AC_STDOUT, "%s%c", src_ptr, IFS); + if(S_ISDIR(statbuf.st_mode)) + fprintf(AC_STDOUT, "%s%c%c", src_ptr, PATH_SEPARATOR, IFS); + else + fprintf(AC_STDOUT, "%s%c", src_ptr, IFS); } } } @@ -612,12 +625,14 @@ static void print_remote_dirlist(char* src_dir, char** not_complete_char) { fprintf(AC_STDOUT, "%s%c", src_full_path, IFS); } else { - int len = strnlen(not_complete_char[0], 255); + int len = strnlen(not_complete_char[0], PATH_MAX); if(!strncmp(not_complete_char[0], src_full_path, len)) { - fprintf(AC_STDOUT, "%s%c", src_full_path, IFS); + if(S_ISDIR(msg.dent.mode)) + fprintf(AC_STDOUT, "%s%c%c", src_full_path, PATH_SEPARATOR, IFS); + else + fprintf(AC_STDOUT, "%s%c", src_full_path, IFS); } } - } finalize: |