-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathirods_completion.bash
77 lines (64 loc) · 2.09 KB
/
irods_completion.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Script for irods i-commands auto-completion with bash
# This script is GPL, blah blah blah...
# Bruno Bzeznik <[email protected]> 10/2011
#
# Simply source this script as follows:
# . irods_completion.bash
# and enjoy <tab> key
# Feel free to improve!
#
# Updated 2022/09/16 Terrell Russell
# - fix setting and unsetting IRODS_CWD (for 4.2+)
#
# Irods command to auto-complete
command_list="ibun icd ichksum ichmod icp iget ils imeta imkdir imv iphybun iphymv irm irmtrash irsync itrim iput"
# Completion function that gets the files list from irods
_ils() {
local cur prev dirname basename base list
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Set irods current directory
export IRODS_CWD=$(ipwd)
# Generate the list of irods files
if [[ $cur == "" ]] ; then
dirname=""
basename=""
elif [[ $cur == */ ]] ; then
dirname=$cur
basename=""
else
dirname="$(dirname ${cur})/"
if [[ $dirname == "." ]] ; then dirname="" ; fi
basename=$(basename ${cur})
fi
list=`ils ${dirname}| perl -ne "/^ / || next; s|^ ([^C])|\1|; s|^ C-.*/(.*)|\1/|; print;"`
# Count the number of arguments that are not options
# (that do not begin by a dash)
# TODO
# to be used in place of $COMP_CWORD into the following tests
# Case of "iput", first arg is a local file
if [ $1 = "iput" -a $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -o default ${cur}) )
# Case of "iget", second arg is a local file
elif [ $1 = "iget" -a $COMP_CWORD -eq 2 ]; then
COMPREPLY=( $(compgen -o default ${cur}) )
# Case of "irsync", manage i: prefix
elif [ $1 = "irsync" ]; then
if [[ $cur == i:* ]]; then
base=${cur:2}
COMPREPLY=( $(compgen -W "$list \ " ${base} ) )
else
COMPREPLY=( $(compgen -P i: -W "$list \ " ${cur} ) )
COMPREPLY+=( $(compgen -o default ${cur}) )
fi
# General case
else
COMPREPLY=( $(compgen -P "$dirname" -W "$list" ${basename}) )
fi
# Unset irods current directory
unset IRODS_CWD
}
# Complete the specified commands
complete -o nospace -F _ils $command_list