4 # Email : hayao@fascode.net
7 # Mastodon: @kokkiemouse@mstdn.jp
8 # Email : kokkiemouse@fascode.net
10 # (c) 2019-2021 Fascode Network.
19 bookmark_file="${HOME}/.config/gtk-3.0/bookmarks"
25 for _file in "${_list[@]}"; do
26 if [[ -f ${_file} ]]; then
28 elif [[ -d ${_file} ]]; then
35 echo "usage ${0} [options] [command]"
37 echo " General options:"
38 echo " -f | --force Force overwriting"
39 echo " -s | --simulation Enable simulation"
40 echo " -h | --help This help message and exit"
42 echo " General command:"
43 echo " add <dir> Add a item to the sidebar"
44 echo " delete <dir> Delete item from the sidebar"
45 echo " alldelete Delete all sidebar items"
46 echo " init Initializes the sidebar"
47 echo " help This help message and exit"
51 if [[ "${simulation}" = true ]]; then
54 echo "${@}" >> "${bookmark_file}"
63 if [[ ! -d "$(dirname "${bookmark_file}")" ]]; then
64 mkdir -p "$(dirname "${bookmark_file}")"
66 if [[ ! -f "${bookmark_file}" ]]; then
67 touch "${bookmark_file}"
72 if [[ "${simulation}" = false ]]; then
77 if [[ ! -d "${dir}" ]]; then
78 _msg_error "${dir} does not exist."
81 output "file://${dir} $(basename "${dir}")"
88 if [[ ! -f "${bookmark_file}" ]]; then
89 _msg_error "Bookmark file does not exist."
92 local _dir _count _line_contain _remove_line=() _url _remove_count i=1
93 for (( i = 1; i <= "${#}"; i++)); do
95 _dir="$(eval echo '$'${i})"
96 _url="$(realpath "${_dir}" | sed "s/ /%20/g")"
98 for _count in $(seq 1 $(cat "${bookmark_file}" | wc -l )); do
99 _line_contain="$(cat "${bookmark_file}" | head -n "${_count}" | tail -n 1 | cut -d ' ' -f 1)"
100 _line_contain="${_line_contain#file://}"
101 if [[ "${_url}" = "${_line_contain}" ]] || [[ "${_url}" = "file://${_line_contain}" ]]; then
102 _remove_line+=("${_count}")
106 if (( "${#_remove_line[@]}" == 0 )); then
107 _msg_error "${_dir} is not registered in the sidebar."
110 for _count in ${_remove_line[@]}; do
111 if [[ "${simulation}" = true ]]; then
112 sed "${_count}d" "${bookmark_file}"
114 _count="$(( _count - _remove_count ))"
115 sed -i "${_count}d" "${bookmark_file}"
116 _remove_count="$(( _remove_count + 1 ))"
123 if [[ "${simulation}" = false ]]; then
124 remove "${bookmark_file}"
128 source "${HOME}/.config/user-dirs.dirs"
131 "${XDG_DOCUMENTS_DIR}"
132 "${XDG_DOWNLOAD_DIR}"
134 "${XDG_PICTURES_DIR}"
139 for dir in "${init_dirs[@]}"; do
140 output "file://${dir} $(basename "${dir}")"
146 # Argument analysis and processing
149 _opt_long="force,help,fascodelive,t-mart,takebayashi,simulation"
150 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
151 if [[ ${?} != 0 ]]; then
182 echo "さすが店長、青春ブタ野郎だね"
188 echo "竹林さん。チノちゃんかわいい最高!!"
193 if [[ "$(basename $0)" == "alterlinux-gtk-bookmarks" ]]; then
194 echo "さすが店長、青春ブタ野郎だね"
196 echo "竹林さん。チノちゃんかわいい最高!!"
207 _msg_error "Invalid argument '${1}'"
219 if [[ -z "${*}" ]]; then
220 _msg_error "Please specify a directory."
229 if [[ "${simulation}" = false ]]; then
230 remove "${bookmark_file}"
235 if [[ -f "${bookmark_file}" ]] && [[ "${force}" = false ]] && [[ "${simulation}" = false ]] && [[ -n "$(cat "${bookmark_file}" 2>/dev/null)" ]]; then
236 _msg_error "The sidebar already exists. Use -f to force initialization."
244 if [[ -z "${*}" ]]; then
245 _msg_error "Please specify a directory."
257 _msg_error "Please specify a command."
262 if [[ "${fascodelive}" = true ]]; then
263 remove "${HOME}/.config/autostart/gensidebar.desktop"