_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;
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
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
#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);
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",
goto finalize;
}
struct dirent* de;
+ struct stat statbuf;
while((de = readdir(d))) {
char* file_name = de->d_name;
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;
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);
}
}
}
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: