Skip to content

Commit

Permalink
adding gnome trash helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Oshuma committed Oct 26, 2010
1 parent 7eb7447 commit 90b074e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
54 changes: 54 additions & 0 deletions bin/trash
@@ -0,0 +1,54 @@
#!/usr/bin/env ruby

# Command line tool for Gnome users to send something to the Trash (with restore info).
# TODO: Support trashing files of the same name.
class Janitor

TRASH_DIR = File.expand_path(File.join(ENV['HOME'], '.local/share/Trash'))
FILES_DIR = File.join(TRASH_DIR, 'files')
INFO_DIR = File.join(TRASH_DIR, 'info')

class << self
def sweep!(files = [])
files.each { |file| trash!(file) }
end

def trash!(file)
return unless File.exists?(file)
$stdout.puts "Trashing #{file}"
create_info_for(file)
move_to_trash(file)
end

private

def create_info_for(file)
info_file = File.join(INFO_DIR, "#{file}.trashinfo")
raise "Info file exists for #{file}: #{info_file}" if File.exists?(info_file)

deletion_date = Time.now.strftime("%Y-%m-%dT%H:%M:%S")

File.open(info_file, 'w') do |info|
info.puts "[Trash Info]"
info.puts "Path=#{File.expand_path(file)}"
info.puts "DeletionDate=#{deletion_date}"
end
end

def move_to_trash(file)
system "mv #{file} #{FILES_DIR}"
end

end # self
end # Janitor


if __FILE__ == $0
if ARGV.empty?
$stderr.puts "No file(s) given!\n"
$stderr.puts "Usage: #{File.basename($0)} <file1>..<fileN>"
exit
end

Janitor.sweep!(ARGV)
end
1 change: 1 addition & 0 deletions lib/alias.zsh
Expand Up @@ -30,6 +30,7 @@ alias rails='nocorrect rails'
alias gemi='gem install --no-ri --no-rdoc '
alias sgemi='sudo gem install --no-ri --no-rdoc '
alias bundle='nocorrect bundle'
alias autotest='nocorrect autotest'

# misc
alias pfind='ps aux |grep '
Expand Down
16 changes: 8 additions & 8 deletions zshrc
Expand Up @@ -7,12 +7,12 @@
export ZSH_HOME=$HOME/.zsh

# Bindings
bindkey -e
bindkey '^A' beginning-of-line
bindkey '^E' end-of-line
bindkey '^r' history-incremental-search-backward
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
# bindkey -v
# bindkey '^A' beginning-of-line
# bindkey '^E' end-of-line
# bindkey '^r' history-incremental-search-backward
# bindkey '^[[A' up-line-or-search
# bindkey '^[[B' down-line-or-search

# Completion
autoload -Uz compinit
Expand Down Expand Up @@ -41,12 +41,12 @@ zle -N self-insert url-quote-magic
# ----------------------
# variables
# ----------------------
# export PATH=$PATH:/sbin:/usr/sbin
export PATH=$PATH:$HOME/.zsh/bin
export EDITOR=/usr/bin/vim
export GREP_OPTIONS='--color=auto'
export LC_ALL=C
export PAGER=less
export LESS='-M -R -X'
export LESS='-F -M -R -X'
export IRB_HISTORY_FILE=$HOME/.irb_history


Expand Down

0 comments on commit 90b074e

Please sign in to comment.