4 # Email : hayao@fascode.net
6 # (c) 2019-2021 Fascode Network.
15 bookmark_file="${HOME}/.config/gtk-3.0/bookmarks"
21 for _file in "${_list[@]}"; do
22 if [[ -f ${_file} ]]; then
24 elif [[ -d ${_file} ]]; then
31 echo "usage ${0} [options] [command]"
33 echo " General options:"
34 echo " -f | --force Force overwriting"
35 echo " -s | --simulation Enable simulation"
36 echo " -h | --help This help message and exit"
38 echo " General command:"
39 echo " add <dir> Add a item to the sidebar"
40 echo " delete <dir> Delete item from the sidebar"
41 echo " alldelete Delete all sidebar items"
42 echo " init Initializes the sidebar"
43 echo " help This help message and exit"
47 if [[ "${simulation}" = true ]]; then
50 echo "${@}" >> "${bookmark_file}"
59 if [[ ! -d "$(dirname "${bookmark_file}")" ]]; then
60 mkdir -p "$(dirname "${bookmark_file}")"
62 if [[ ! -f "${bookmark_file}" ]]; then
63 touch "${bookmark_file}"
68 if [[ "${simulation}" = false ]]; then
73 if [[ ! -d "${dir}" ]]; then
74 _msg_error "${dir} does not exist."
77 output "file://${dir} $(basename "${dir}")"
84 if [[ ! -f "${bookmark_file}" ]]; then
85 _msg_error "Bookmark file does not exist."
88 local _dir _count _line_contain _remove_line=() _url _remove_count i=1
89 for (( i = 1; i <= "${#}"; i++)); do
91 _dir="$(eval echo '$'${i})"
92 _url="$(realpath "${_dir}" | sed "s/ /%20/g")"
94 for _count in $(seq 1 $(cat "${bookmark_file}" | wc -l )); do
95 _line_contain="$(cat "${bookmark_file}" | head -n "${_count}" | tail -n 1 | cut -d ' ' -f 1)"
96 _line_contain="${_line_contain#file://}"
97 if [[ "${_url}" = "${_line_contain}" ]] || [[ "${_url}" = "file://${_line_contain}" ]]; then
98 _remove_line+=("${_count}")
102 if (( "${#_remove_line[@]}" == 0 )); then
103 _msg_error "${_dir} is not registered in the sidebar."
106 for _count in ${_remove_line[@]}; do
107 if [[ "${simulation}" = true ]]; then
108 sed "${_count}d" "${bookmark_file}"
110 _count="$(( _count - _remove_count ))"
111 sed -i "${_count}d" "${bookmark_file}"
112 _remove_count="$(( _remove_count + 1 ))"
119 if [[ "${simulation}" = false ]]; then
120 remove "${bookmark_file}"
124 source "${HOME}/.config/user-dirs.dirs"
127 "${XDG_DOCUMENTS_DIR}"
128 "${XDG_DOWNLOAD_DIR}"
130 "${XDG_PICTURES_DIR}"
135 for dir in "${init_dirs[@]}"; do
136 output "file://${dir} $(basename "${dir}")"
142 # Argument analysis and processing
145 _opt_long="force,help,fascodelive,t-mart,takebayashi,simulation"
146 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
147 if [[ ${?} != 0 ]]; then
178 echo "さすが店長、青春ブタ野郎だね"
189 if [[ "$(basename $0)" == "alterlinux-gtk-bookmarks" ]]; then
190 echo "さすが店長、青春ブタ野郎だね"
203 _msg_error "Invalid argument '${1}'"
215 if [[ -z "${*}" ]]; then
216 _msg_error "Please specify a directory."
225 if [[ "${simulation}" = false ]]; then
226 remove "${bookmark_file}"
231 if [[ -f "${bookmark_file}" ]] && [[ "${force}" = false ]] && [[ "${simulation}" = false ]] && [[ -n "$(cat "${bookmark_file}" 2>/dev/null)" ]]; then
232 _msg_error "The sidebar already exists. Use -f to force initialization."
240 if [[ -z "${*}" ]]; then
241 _msg_error "Please specify a directory."
253 _msg_error "Please specify a command."
258 if [[ "${fascodelive}" = true ]]; then
259 remove "${HOME}/.config/autostart/gensidebar.desktop"