ฉันจะตั้งค่าโหมดมุมมอง Nautilus ซ้ำ ๆ ให้เป็นแผนผังต้นไม้ได้อย่างไร


11

Nautilus 3.4 ช่วยให้คุณสามารถตั้งค่าโหมดมุมมองเริ่มต้น นอกจากนี้ยังจดจำการตั้งค่ามุมมองที่กำหนดเองของคุณสำหรับโฟลเดอร์เฉพาะ

สิ่งที่ฉันอยากจะทำคือการกำหนดโหมดมุมมองสำหรับไดเรกทอรีและไดเรกทอรีย่อยทั้งหมดในไดเรกทอรีต้นไม้ที่เฉพาะเจาะจง ผ่านแต่ละโฟลเดอร์เพื่อเปลี่ยนโหมดการดูด้วยตนเองจะใช้เวลานานเกินไป

มีวิธีใดบ้างที่ฉันสามารถทำได้ อาจผ่านสคริปต์ Nautilus ที่แก้ไขgvfs-metadataหรือไม่

คำตอบ:


10

ภาพรวม

ในการค้นหาข้อมูลเมตาสำหรับโฟลเดอร์ที่คุณต้องใช้คำสั่ง gvfs-info foldername

ตัวอย่างเช่น gvfs-info /home/homefolder/Desktop

ในรายการที่ส่งคืนคุณจะเห็นแอททริบิวmetadata::nautilus-default-viewซึ่งอธิบายถึงมุมมองเริ่มต้น

คุณสามารถเปลี่ยนคุณสมบัตินี้โดยใช้คำสั่ง gvfs-set_attribute foldername attribute newvalue

ตัวอย่างเช่น:

gvfs-set-attribute /home/homefolder/Desktop "metadata::nautilus-default-view" "OAFIID:Nautilus_File_Manager_Icon_View"

ต้นฉบับ

ตอนนี้ฉันต้องยอมรับทักษะการเขียนสคริปต์ทุบตีของฉันไม่ได้ดีที่สุด แต่ที่นี่ไป - สคริปต์ของฉันด้านล่างจะช่วยให้คุณสามารถรีเซ็ตมุมมองทั้งหมดด้านล่างชื่อโฟลเดอร์ที่กำหนด

ไวยากรณ์:

folderreset [OPTION] full_base_directory_name

เช่นนี้จะรีเซ็ตเป็นกะทัดรัดดูโฟลเดอร์ทั้งหมดด้านล่าง /home/homefolder/Desktop

folderreset -c /home/homefolder/Desktop

ใช้folderreset -hสำหรับไวยากรณ์

อย่าลังเลที่จะคนจรจัดและแก้ไข


#!/bin/bash

#Licensed under the standard MIT license:
#Copyright 2013 fossfreedom.
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

################################ USAGE #######################################

usage=$(
cat <<EOF
Usage:
$0 [OPTION] base_full_directory_name 

 -h, --help     display this help
 -l, --list     set to list view
 -i, --icon     set to icon view
 -c, --compact  set to compact view

for example

$0 -i /home/myhome/Desktop

This will reset all directories BELOW /home/myhome/Desktop

EOF
)

########################### OPTIONS PARSING #################################

#parse options
TMP=`getopt --name=$0 -a --longoptions=list,icon,compact,help -o l,i,c,h -- $@`

if [[ $? == 1 ]]
then
    echo
    echo "$usage"
    exit
fi

eval set -- $TMP

#default values
META=OAFIID:Nautilus_File_Manager_List_View

until [[ $1 == -- ]]; do
    case $1 in
        -l|--list)
            META=OAFIID:Nautilus_File_Manager_List_View
            ;;
        -i|--icon)
            META=OAFIID:Nautilus_File_Manager_Icon_View
            ;;
        -c|--compact)
            META=OAFIID:Nautilus_File_Manager_Compact_View
            ;;
        -h|--help)
            echo "$usage"
            exit
            ;;
    esac
    shift # move the arg list to the next option or '--'
done
shift # remove the '--', now $1 positioned at first argument if any

if [ ! -d "$1" ]
then
        echo "Directory does not exist!"
        exit 4
fi

find "$1"/* -type d | while read "D"; do gvfs-set-attribute "$D" "metadata::nautilus-default-view" "$META" &>/dev/null; done

กระดาษห่อ GUI

นี่คือสคริปต์ตัวห่อ GUI อย่างง่ายที่สามารถใช้เพื่อตั้งค่าโหมดมุมมองจากเมนูบริบทของสคริปต์ Nautilus:

#!/bin/bash

# Licensed under the standard MIT license
# (c) 2013 Glutanimate (http://askubuntu.com/users/81372/)

FOLDERRESET="./folderreset.sh"
WMICON=nautilus
THUMBICON=nautilus
WMCLASS="folderviewsetter"
TITLE="Set folder view"

DIR="$1"

checkifdir(){
if [[ -d "$DIR" ]] 
  then
      echo "$DIR is a directory"
  else
      yad --title="$TITLE" \
          --image=dialog-error \
          --window-icon=dialog-error \
          --class="$WMCLASS" \
          --text="Error: no directory selected." \
          --button="Ok":0
      exit
fi
}

setviewtype (){
VIEWTYPE=$(yad \
    --width 300 --entry --title "$TITLE" \
    --image=nautilus \
    --button="ok:2" --button="cancel" \
    --text "Select view mode:" \
    --entry-text \
    "list" "icon" "compact")

 if [ -z "$VIEWTYPE" ]
   then
       exit
 fi

}  


checkifdir
setviewtype

"$FOLDERRESET" --"$VIEWTYPE" "$DIR"

สคริปต์ขึ้นอยู่กับทางแยก zenity yadซึ่งสามารถติดตั้งได้จากPPAนี้ ตรวจสอบให้แน่ใจว่าชี้FOLDERRESET=ไปที่ตำแหน่งของfolderresetสคริปต์ในระบบของคุณ


ฉันใช้ Nautilus 3.6.3 (Ubuntu 13.04) และไม่มีแอตทริบิวต์ดังกล่าวmetadata::nautilus-default-view:(
Radu Rădeanu

1
@ RaduRădeanu - อ๋อ Gnome-Devs ฉีกสิ่งต่างๆมากมายจาก nautilus ใน v3.6: /
fossfreedom
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.